url重写为短网址

时间:2013-07-30 08:54:48

标签: php regex .htaccess mod-rewrite

好日子的家伙,我需要你的帮助这个网址重写。

这是我想要做的两次重写。

1)我想从网址中取出.php即使我的文件保存为.php

2)我想重写下面的网址

如果你能帮助我。它会很可爱。感谢

1 个答案:

答案 0 :(得分:1)

启用mod_rewrite.htaccesshttpd.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]