如何重定向localhost/test/test.php以重定向localhost/test/test
这是我的.htaccess代码如何重定向localhost/test/test.php以重定向localhost/test/test,php,apache,.htaccess,Php,Apache,.htaccess,这是我的.htaccess代码 Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On**RewriteBase /RewriteRule ^test/?$ test.php [L,NC] 但它并没有将我重定向到“test”。在.htacces中是否有任何错误,或者我必须进行一些Apache配置更改。 谢谢你试试这个 RewriteEngine on RewriteCond %{REQUEST_FIL
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On**RewriteBase /RewriteRule ^test/?$ test.php [L,NC]
但它并没有将我重定向到“test”。在.htacces中是否有任何错误,或者我必须进行一些Apache配置更改。
谢谢你试试这个
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
是您在/test/目录下的
.htaccess
吗?是的,这是我的.htaccess。我建议您使用虚拟主机,这将为您在使用本地主机时节省一些麻烦。谢谢。这是最好的
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]