使用mod_rewrite和mod_alias中(重定向301)一起在.htaccess? [英] Using mod_rewrite and mod_alias (redirect 301) together in .htaccess?

查看:230
本文介绍了使用mod_rewrite和mod_alias中(重定向301)一起在.htaccess?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站用一套旧的.html和.PHP网页已投入CMS。

I have a site with a set of old .html and .php pages that have been put into a CMS.

目前在.htaccess文件中有大约30 mod_alias中重定向以下形式:

Currently in the .htaccess file there are about 30 mod_alias redirects in the following form:

redirect 301 /oldpage1.html http://www.example.com/newpage1.php
redirect 301 /oldpage2.php http://www.example.com/newpage2.php
redirect 301 /oldpage3.php http://www.example.com/newpage3.php

但是,我们要使用mod_rewrite有pretty的网址在CMS,将采取的形式 http://www.example.com/pagename.php ,所以也有以下内容:

But we want to use mod_rewrite to have pretty URLs in our CMS, which will take the form http://www.example.com/pagename.php, so also have the following:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1

目前的时刻都被一起应用,这导致:

At the moment both are being applied together, which results in:

http://www.example.com/newpage1.php?page=oldpage1.html

我怎么能只适用于不匹配已经由mod_alias中重定向301语句,这样会发生以下情况重写规则:

How can I apply the rewrite rule only when no match has been made by the mod_alias redirect 301 statements, so that the following occurs:

http://www.example.com/oldpage1.html - >重定向到 - > http://www.example.com/newpage1.php - >被视为 - > http://www.example.com/index.php?page=/newpage1.php

http://www.example.com/oldpage1.html -> redirects to -> http://www.example.com/newpage1.php -> which is treated as -> http://www.example.com/index.php?page=/newpage1.php

任何提示将非常AP preciated?谢谢你。

Any hints would be very much appreciated? Thanks.

推荐答案

我发现href="http://www.greywyvern.com/?post=358" rel="nofollow">大的解释

I found the answer in a great explanation of mod_rewrite and mod_alias

问题在于mod_rewrite的总是发生mod_alias中之前,无论放置在.htaccess的量级。这是需要这种局面的顺序相反。

The problem is that mod_rewrite always occurs before mod_alias, regardless of the order the are placed in .htaccess. This is the reverse of the order required for this situation.

的技巧是使用重写规则[R = 301] 而不是重定向301 ,因此使用mod_rewrite的的一切,而不是用mod_alias中混了。

The trick is to use RewriteRule [R=301] instead of redirect 301, and hence use mod_rewrite for everything instead of mixing it with mod_alias.

完整的解决方案如下:

RewriteEngine on
RewriteBase /

RewriteRule ^oldpage1.html /newpage1.php [R=301,L]
RewriteRule ^oldpage2.php /newpage2.php [R=301,L]
RewriteRule ^oldpage3.php /newpage3.php [R=301,L]

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

这篇关于使用mod_rewrite和mod_alias中(重定向301)一起在.htaccess?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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