新的.htaccess文件(仍无法正常工作,它把我送到localhost/xampp
为什么我不能将index.php重定向到域?
RewriteEngine on
RewriteBase /sample/
# set root to index.php
DirectoryIndex index.php
# prevent directory listing
Options -Indexes
# remove index.php
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*)index.php$ $1 [R=301,L,NC]
# removing extensions
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+)/?$ $1.php [L]
老的.htaccess文件如下:
RewriteEngine on
# set root to index.php
DirectoryIndex index.php
# prevent directory listing
Options -Indexes
# removing extensions
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
# remove index.php
Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://localhost/sample/ [R=301,L]
域是http://localhost/sample/
我已经试过,谷歌给了我很多东西。但他们没有工作。我每次去localhost/sample/index.php
它不重定向到localhost/sample/
。我还使用了Redirect 301 /index.php /
。
我试过
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]
但它会将我送到http://localhost/xampp/splash.php
。
我还是新来的.htaccess所以我真的不知道我做错了什么。我已经尝试了OP给出答案的答案。
我猜你是从'/''到HTTP重定向其他一些规则://本地主机/ XAMPP重定向规则之前/ splash.php' – Quentin
规则匹配任何东西,并且是'[L]',所以在它将被测试之后没有其他规则。 – deceze
加 'RewriteBase /'也 –