我试图重写这样的网址:
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'中的重写规则):
更新
这是文件夹Corporate
# 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]
答案 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为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