Regex 用slash/using.htaccess替换php扩展名
我想用Regex 用slash/using.htaccess替换php扩展名,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,我想用.htaccess重写php扩展。我想用斜杠/替换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
.htaccess
重写php扩展。我想用斜杠/
替换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} ^[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 [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} ^[A-Z]{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]
使用Apache2.2和Apache1.3.7进行测试
RewriteEngine On
RewriteBase /
你只需要一句话就可以做到
RewriteRule ^(.*)/$ /$1.php [L]
Apache2.2
对于http://www.domain.com/services.php
然后带上它
http://www.domain.com/services
或http://www.domain.com/services/
Apache 1.3.7
RewriteEngine On
RewriteBase /
如果你愿意
http://www.domain.com/services/
您需要。/$
RewriteRule ^(.*)//$ /$1.php [L]
更新
http.conf
LoadModule rewrite_module modules/mod_rewrite.so
可能的错误选项:必须具有多视图
文档根
<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/">
这对我很有效。祝你好运 当您获得404时,浏览器中会显示什么URL?这是唯一的规则还是您有更多的规则?根据您的建议,这是完整的源代码:RewriteBase上的RewriteEngine/RewriteRule^(.*)/$/$1.php[L]RewriteRule^(.*)/$/$/$1.php[L]?@Hawk:您只需要选择一种可能性<使用
RewriteRule^(.*)/$/$1.php[L]
或RewriteRule^(.*)/$/$1.php[L]
在RewriteBase上重写引擎/!你看到我的更新了吗??