我怎样才能让我的所有的URL扩展名,没有斜线。并重定向.php然后斜线无法比拟的? [英] How can I make all my urls extensionless, without trailing slash. And redirect the .php and trailing slash to none?

查看:159
本文介绍了我怎样才能让我的所有的URL扩展名,没有斜线。并重定向.php然后斜线无法比拟的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我要让我所有的网址均匀干净。这意味着所有的网址没有扩展名,也没有斜线,如果一个人确实在以.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

这篇关于我怎样才能让我的所有的URL扩展名,没有斜线。并重定向.php然后斜线无法比拟的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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