.htaccess compulsory www and removing php extension
如果有人访问:http://domain.com,我想将他重定向到http://www.domain.com,如果有人访问:http://domain.com/remove.php,我想 将他重定向到http://www.domain.com/remove
因此,基本上,如果没有请求子域,我想在URL的开头添加一个www,并且我还希望用户重定向到没有PHP扩展名的URL,以防他尝试访问一个URL。 我知道,如何接受不具有.php扩展名的页面,但是现在我正在寻找上述所有功能的代码以及重定向代码,该代码将在用户尝试将用户重定向到非PHP扩展名页面时 用PHP扩展名访问
因此,如果他访问,他会到达...
- http://www.domain.com/index.php http://www.domain.com/index
- http://domain.com/index.php http://www.domain.com/index
- http://domain.com/ http://www.domain.com
1 2 3 4 5 6 7 | 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] |