好日子的家伙,我需要你的帮助这个网址重写。
这是我想要做的两次重写。
1)我想从网址中取出.php
即使我的文件保存为.php
2)我想重写下面的网址
如果你能帮助我。它会很可爱。感谢
答案 0 :(得分:1)
启用mod_rewrite
和.htaccess
至httpd.conf
,然后将此代码放入DOCUMENT_ROOT/.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[\s?] [NC]
RewriteRule ^ %1 [R=301,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]