我在localhost中有一个网站 - ourallnews
。我想将所有关键字index, index.php, index.html
重定向到网站根目录 - localhost/ourallnews/
。我在.htaccess
中应用了以下规则,但它被重定向到 - localhost/dashboard/
。如何解决?
RewriteEngine on
RewriteBase /ourallnews/
RewriteRule ^(.*)index\.(php|html?)$ /$1 [R=301,NC,L]
RewriteCond %{THE_REQUEST} /category(?:\.php)?\?cat=([^\s&]+) [NC]
RewriteRule ^ %1? [R=301,L]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)$ category.php?cat=$1 [L,QSA]
答案 0 :(得分:1)
如果你正在使用RewriteBase
,那么只需在重定向时使用相对链接:
RewriteEngine on
RewriteBase /ourallnews/
RewriteRule ^(.*)index\.(?:php|html?)$ $1 [R=301,NC,NE,L]
RewriteCond %{THE_REQUEST} /category(?:\.php)?\?cat=([^\s&]+) [NC]
RewriteRule ^ %1? [R=301,L]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)/?$ category.php?cat=$1 [L,QSA]
确保清除浏览器缓存或使用新的浏览器进行测试。