mod_rewrite的热媒假子目录热媒、子目录、mod_rewrite

2023-09-02 01:13:54 作者:不够成熟°

我有一个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]