我必须重定向一些url。
例如,如果网址是
www.example.com/shop valid
www.example.com/shop/red-product need redirection to www.example.com/red-product
www.example.com/shop/green need redirection to www.example.com/green
www.example.com/shop/any-string need redirection to www.example.com/any-string
我该怎么做。请帮忙。
我当前的htacess文件是
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Redirect 301 /bio/ https://www.example.com/bio/
Options -Indexes
答案 0 :(得分:1)
以下规则应该起作用,因为我们仅在购物后匹配组。
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/shop/(.*)
RewriteRule ^ http://www.example.com/%1 [R]
答案 1 :(得分:1)
您可以用以下代码替换您的代码:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^shop/(.+)$ /$1 [L,NC,NE,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>