htaccess文件没有任何影响

时间:2016-03-18 07:43:05

标签: php apache .htaccess mod-rewrite

我试图重写这样的网址:

  

www.mywebsite.com/product/a-product-name-here/92341

  

www.mywebsite.com/our-products/a-product-name-here/92341

我正在使用以下rewriterule:

RewriteRule ^product/(.*)$ our-products/$  [R=301,L]

根据this在线工具,它应该可以解决问题。我把它放在网上,但它并没有影响任何事情。

AllowOverride在我的主机上处于活动状态。

我的文件夹结构是这样的(尝试了两个.htaccess'中的重写规则): folder structure

更新

这是文件夹Corporate

中的.htaccess内容
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /corporate/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /corporate/index.php [L]
</IfModule>

# END WordPress

这是product文件夹中.htaccess文件的内容:

AddDefaultCharset utf-8
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.+) index.php?a=$1 [nc]

1 个答案:

答案 0 :(得分:0)

好的,据我所知,你的问题可以分为两部分。

重定向公共网址

您希望将公开网址example.com/product/foo-bar/1234重定向到example.com/our-products/foo-bar/1234。这可以通过anubhava已经发布的规则来实现,稍微修改为仅匹配数字:

除了.htaccess之外,

将其放在您的根index.php

RewriteRule ^product/((.+)/(\d+))$ /our-products/$1 [R=301,L]

在内部将外部URL映射到脚本

然后,外部URL为example.com/our-products/foo-bar/1234,它在服务器计算机上实际上不存在,因此失败了404.

因此,您必须将其映射到包含实际逻辑的脚本。

RewriteRule ^our-products/(.+)$ /product/index.php?a=$1 [L]

这假设您的脚本将接受a参数。

更改后的.htaccess个文件

这是.htaccess

文件夹中的Corporate内容
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^product/((.+)/(\d+))$ /our-products/$1 [R=301,L]
    RewriteRule ^our-products/(.+)$ /product/index.php?a=$1 [L]
</IfModule>

# BEGIN WordPress
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /corporate/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /corporate/index.php [L]
</IfModule>

# END WordPress

这是产品文件夹中.htaccess文件的内容:

AddDefaultCharset utf-8
Options +FollowSymlinks
相关问题