如何重定向到相对 url htaccess apache 2.22
How to redirect to relative url htaccess apache 2.22
我正在尝试将 rootdomain.com/index.php
重定向到 rootdomain.com
,并且只是根目录,而不是任何以 index.php
结尾的子目录
我试过了
Redirect 302 ^(.*)index.php$ //
Redirect 302 ^(.*)index.php$ /
RewriteRule ^(.*)index.php$ / [R=302,L]
RewriteRule ^(.*)index.php$ / [R=302,L]
RewriteRule ^(.*)index.php$ / [R=302,L,QSD]
RewriteRule ^(.*)index.php$ / [R=302,L,QSD]
(我知道还有其他类似的问题。但是其他问题的解决方案对我不起作用)
在你的 .htaccess
中试试这个,它应该从你的 URL 中删除 index.php
:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/ [L]
您可以使用此通用规则从任何相对路径或根路径中删除 index.php
:
# remove index.php from root
RewriteCond %{THE_REQUEST} \s/+index\.php[?\s] [NC]
RewriteRule ^ / [L,R=301,NE]
我正在尝试将 rootdomain.com/index.php
重定向到 rootdomain.com
,并且只是根目录,而不是任何以 index.php
我试过了
Redirect 302 ^(.*)index.php$ //
Redirect 302 ^(.*)index.php$ /
RewriteRule ^(.*)index.php$ / [R=302,L]
RewriteRule ^(.*)index.php$ / [R=302,L]
RewriteRule ^(.*)index.php$ / [R=302,L,QSD]
RewriteRule ^(.*)index.php$ / [R=302,L,QSD]
(我知道还有其他类似的问题。但是其他问题的解决方案对我不起作用)
在你的 .htaccess
中试试这个,它应该从你的 URL 中删除 index.php
:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/ [L]
您可以使用此通用规则从任何相对路径或根路径中删除 index.php
:
# remove index.php from root
RewriteCond %{THE_REQUEST} \s/+index\.php[?\s] [NC]
RewriteRule ^ / [L,R=301,NE]