htaccess的强制性WWW和删除php扩展 [英] .htaccess compulsory www and removing php extension

查看:142
本文介绍了htaccess的强制性WWW和删除php扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果一个人访问: http://domain.com ,我想重定向他的 http://www.domain.com ,如果一个人访问 http://domain.com/remove.php ,我想重定向他的 http://www.domain.com/remove

因此​​,基本上,我想补充的 WWW 的URL中的的开始,如果一个子域不被要求,然后我也希望用户被重定向到一个网址没有PHP扩展的情况下,他尝试访问之一。我知道,如何接受不具有.php扩展的网页,但现在我在找一个$ C $下的所有上述功能以及重定向code这将重定向用户在非PHP扩展页面的情况下,他试图访问一个具有PHP扩展

所以,如果他访问,他到达...

解决方案

  RewriteEngine叙述上
#首先强制WWW(不区分大小写)
的RewriteCond%{HTTP_HOST}!^ WWW \ .EXAMPLE \ .COM $ [NC]
(。*)重写规则^ $ HTTP://www.example.com$1 [L,R = 301,QSA]

#这条规则重写的.php关结束。
重写规则^ /([A-ZA-Z0-9)\ PHP http://www.example.com/$1 [L,R,QSA]
 

If a person visits: http://domain.com, I want to redirect him to http://www.domain.com and if a person visits: http://domain.com/remove.php, I would like to redirect him to http://www.domain.com/remove

So basically, I want to add a www in the beginning of the url if a subdomain is not being requested and I also want the user to be redirected to a URL without the PHP extension in case he tries to access one. I know, how to accept pages which don't have .php extension but now I'm looking to a code for all the above features along with a redirection code which will redirect the user to a non PHP extension page in case he tries to visit one with the PHP extension

So, if he visits, he reaches ...

解决方案

RewriteEngine On
# First force the www (ignoring case)
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301,QSA]

# And this rule rewrites the .php off the end.
RewriteRule ^/([A-Za-z0-9)\.php http://www.example.com/$1 [L,R,QSA]

这篇关于htaccess的强制性WWW和删除php扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆