Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何重定向localhost/test/test.php以重定向localhost/test/test_Php_Apache_.htaccess - Fatal编程技术网

如何重定向localhost/test/test.php以重定向localhost/test/test

如何重定向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

这是我的.htaccess代码

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]