我是.htaccess的新手。我已经阅读了文档,但无法使重定向规则发挥作用。
我想要RewriteRule负责以下工作
http://mywebsite.com/restaurants/59393/the-grounds-of-alexandria.htm至
http://mywebsite.com/restaurants/the-grounds-of-alexandria我试过这个
RewriteRule ^(.*)/[0-9]/(.*)$ ^(.*)/(.*)/$ [R=301,L]另外,您如何获得子域并将其放在所有链接的前面,就像这样
http://sydney.mywebsite.com/restaurants/59393/the-grounds-of-alexandria.htm至
http://mywebsite.com/sydney/restaurants/the-grounds-of-alexandria但没有结果。
发布于 2014-11-07 14:56:43
重写这很简单:
http://mywebsite.com/restaurants/59393/the-grounds-of-alexandria.htm
to
http://mywebsite.com/restaurants/the-grounds-of-alexandria重写规则RewriteRule ^(.*)/[0-9]/(.*)$ ^(.*)/(.*)/$ [R=301,L]对于urls来说太全局了。其次,你只要说0-9就意味着只有一位数。
RewriteRule ^([^/]+)/[0-9]+/([^.]+)\.htm$ /$1/$2 [R=301,L](试试这个;)
编辑(关于第二个问题):
http://sydney.mywebsite.com/restaurants/59393/the-grounds-of-alexandria.htm
to
http://mywebsite.com/sydney/restaurants/the-grounds-of-alexandria当然;)在那里,您必须使用RewriteCond。
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^([^\.]+)\.mywebsite\.com/([^/]+)/[0-9]+/([^.]+)\.htm
RewriteRule ^.*$ http://mywebsite.com/%1/%2/%3 [R=301,L]为了进行解释,%1-3可以从要在RewriteRule语句中使用的上一次匹配中使用。这应该适用于每个子域,而且只适用于子域。如果您想要一个特定的子域,可以将第一行调整为^(sidney|othersubdomain|anothersubdomain)\.mywebsite\.com...。
https://stackoverflow.com/questions/26801427
复制相似问题