您好我要让我所有的网址均匀干净。这意味着所有的网址没有扩展名,也没有斜线,如果一个人确实在以.php或斜线输入,它只会者重定向到URL干净。
Hi I want to make all my urls uniformly clean. Which means all my urls have no extensions, nor trailing slash, and if a person does enter in a .php or trailing slash, it would simply redirect the person to the clean url.
为例。 blah.com/blog/today_i_wet_myself.php 和 blah.com/blog/today_i_wet_myself /
Example. blah.com/blog/today_i_wet_myself.php and blah.com/blog/today_i_wet_myself/
既能重定向到
blah.com/blog/today_i_wet_myself
blah.com/blog/today_i_wet_myself
谢谢!
推荐答案
我的虚拟主机最近(2011年9月)更新了自己的Apache服务器,Apache的较新版本,和我的老的.htaccess code,显示扩展名的URL没有不再奏效。大量的复制code之后(这可能曾与旧版本的Apache操作系统)和失败的测试,我能够确定以下code似乎工作我的服务器上,和其他几个人:
My web host recently (Sept 2011) updated their Apache servers to a newer version of Apache, and my old .htaccess code to display extensionless URLs no longer worked. After a considerable amount of copying code (that probably worked with older versions of the Apache OS) and unsuccessfully testing, I was able to determine that the following code seems to work on my server, and several others:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.php [NC,L]
RewriteCond %{THE_REQUEST} ^[A-Z]+ /([^/]+/)*[^.#? ]+.php([#?][^ ]*)? HTTP/
RewriteRule ^(([^/]+/)*[^.]+).php http://www.karlkelman.com/$1 [R=301,L]
给一个尝试 - 在-Multiviews似乎是关键因素,以得到它的工作。当然,你要改变karlkelman.com到你的网址
Give that a try - the "-Multiviews" seemed to be the key element to get it to work. Of course, you'll want to change the "karlkelman.com" to your web address
-Karl
相关推荐
最新文章