.htaccess 重定向到本地主机仪表板而不是项目根目录

.htaccess 重定向到本地主机仪表板而不是项目根目录,.htaccess,.htaccess,我在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] Re

我在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]

如果您使用的是
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]

确保清除浏览器缓存或使用新浏览器进行测试。

关于.htaccess规则,您是genius。我发现你在这个网站上的其他答案解释得很好,也很有帮助。再次感谢