我知道这可以使用mod_rewrite完成,但我不确定,因为我使用的是Xampp,有人说它无法在Windows机器上运行。所以我想我现在甚至无法测试它。
所以如果我有login.php,index.php等......
我希望它们相应地显示为mysite.com/login/
或mysite.com/index/
我怎样才能做到这一点?
答案 0 :(得分:1)
将此代码放在.htaccess
目录下的DOCUMENT_ROOT
:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# specific rule to handle these URLs
RewriteRule ^login/?$ /login.php [L,NC]
RewriteRule ^index/?$ /index.php [L,NC]
# OR a generic once to forward all /foo to /foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]