我的网址格式如下:
http://www.mysite.com/index.php?l=accommodation/lodge/some-place
我想使用htaccess将其重写为这种格式:
http://www.mysite.com/accommodation/lodge/some-place
我该怎么做?我开始尝试使用drupal的htaccess文件,并得到类似的东西:
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?l=$1 [L,QSA]
问题是,如果我输入原始的index.php网址,它仍会显示。它必须重定向到短版本。换句话说,这个:
http://www.mysite.com/index.php?l=accommodation/lodge/some-place
必须转发:
http://www.mysite.com/accommodation/lodge/some-place
思想?
答案 0 :(得分:1)
在规则上方插入此附加规则:
RewriteCond %{THE_REQUEST} \s/+index\.php\?l=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]
这将从外部将http://www.mysite.com/index.php?l=accommodation/lodge/some-place
重定向到http://www.mysite.com/accommodation/lodge/some-place