我想用.htaccess
重写php扩展。 我想用斜杠/
replacephp扩展。 例如,如果我有: http://example.com/about-us.php
: http://example.com/about-us.php
将是http://example.com/about-us/
我怎样才能让这个修改这段代码:
Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / # To externally redirect /dir/foo.php to /dir/foo RewriteCond %{THE_REQUEST} ^[AZ]{3,}\s([^.]+)\.php [NC] RewriteRule ^ %1 [R,L,NC] ## To internally redirect /dir/foo to /dir/foo.php RewriteCond %{REQUEST_FILENAME}.php -f [NC] RewriteRule ^ %{REQUEST_URI}.php [L] RewriteRule .*[^/]$ $0/ [L,R=301]
谢谢大家!!!
您可以使用:
Options +FollowSymLinks -MultiViews RewriteEngine On RewriteBase / # To externally redirect /dir/foo.php to /dir/foo RewriteCond %{THE_REQUEST} ^[AZ]{3,}\s([^.]+)\.php [NC] RewriteRule ^ %1/ [R,L] ## To internally redirect /dir/foo to /dir/foo.php RewriteCond %{REQUEST_FILENAME}.php -f [NC] RewriteRule ^(.+?)/?$ $1.php [L]
经过Apache 2.2和Apache 1.3.7的测试
RewriteEngine On RewriteBase /
你可以用一行来完成
RewriteRule ^(.*)/$ /$1.php [L]
Apache 2.2
为http://www.domain.com/services.php
并得到它
http://www.domain.com/services
或http://www.domain.com/services/
Apache 1.3.7
如果你想
http://www.domain.com/services/
你需要..//$
RewriteRule ^(.*)//$ /$1.php [L]
更新
在http.conf
Loadmodulee rewrite_module modules / mod_rewrite.so
可能的错误选项:必须具有MultiView
的DocumentRoot
<Directory "G:\Programme\Apache Group\Apache\htdocs"> Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all </Directory>
在html头中,包括:
<base href="http://www.yourdomain.com/">
在htacces:
RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f [NC] RewriteRule ^(.+?)/?$ $1.php RewriteCond %{REQUEST_URI} !\.[^./]+$ RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)\.[^.]+$ http://www.yourdomain.com/$1/ [L,R=301]
这对我有用。 祝你好运!