mod_rewrite的热媒假子目录 [英] Mod_rewrite .htm to fake subdirectory

查看:120
本文介绍了mod_rewrite的热媒假子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CMS一个网站,使用了mod_rewrite做出的URL看起来更干净。 previously,干净的网址有扩展名为.htm,但我想过渡给他们看显示为假的子目录,例如:

  http://www.example.com/pagename/
 

我已经制定了两个重写规则重写了这两个老方案和潜在的新的:

 的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(+)。HTM $的index.php?网页= $ 1 [QSA]

的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(+)/ $的index.php?网页= $ 1 [QSA]
 

我的问题是,我试图在规则中使用旧的URL重定向到新的什么都不做。

 的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(+)。HTM $ 1 $ / [R = 302,NC,QSA]
 

解决方案

您不能同时采用两种规则,因为只有他们第一次将应用相同的模式。尝试用新的重定向规则取代你的重写的规则来获得,而不是重定向的旧网址刚刚改写:

 #重定向foo.htm来富/
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。+)\。HTM $ $ 1 / [R = 301,NC]
#改写富/到index.php?网页= FOO
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(+)/ $的index.php?网页= $ 1 [QSA]
 

I have a website with a CMS that uses mod_rewrite to make URLs look cleaner. Previously, the clean URLs had the extension .htm, but I want to transition this to them appearing as fake subdirectories, IE:

http://www.example.com/pagename/

I have two rewrite rules in place to rewrite both the old scheme and the potential new one:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+).htm$ index.php?page=$1 [QSA]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ index.php?page=$1 [QSA]

My problem is that the rule I tried to use to redirect old URLs to new ones does nothing.

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+).htm$ $1/ [R=302,NC,QSA]

解决方案

You can not use two rules with the same pattern as only the first of them will be applied. Try to replace your "rewrite" rule with the new "redirect" rule to get the old URLs redirected instead of just rewritten:

# redirect foo.htm to foo/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.htm$ $1/ [R=301,NC]
# rewrite foo/ to index.php?page=foo
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ index.php?page=$1 [QSA]

这篇关于mod_rewrite的热媒假子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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