2010-02-02 175 views
1

我有一个使用CMSMadeSimple(基于PHP)的新网站设置,但我遇到了问题301使用新设置重定向旧网站URL。由于URL重写导致301重定向的问题

我使用CMS的标准.htaccess文件,它将http://www.example.com/test.html等SEO友好URL转换为http://www.example.com?page=test,但我也需要在此文件中重定向旧URL(ASP站点)。

我当前的.htaccess如下图所示,我已经尝试添加该行

redirect 301 /test.asp http://www.example.com/test.html 

,但是当我这样做的页面重定向到http://www.example.com/test.html?page=test.asp没有http://www.example.com/test.html要求

# BEGIN Optional settings 

# Turns off directory browsing 
# not absolutely essential, but keeps people from snooping around without 
# needing empty index.html files everywhere 
Options -Indexes 

# Deny access to config.php 
# This can be useful if php ever breaks or dies 
# Use with caution, this may break other functions of CMSms that use a config.php 
# file. This may also break other programs you have running under your CMSms 
# install that use config.php. You may need to add another .htaccess file to those 
# directories to specifically allow config.php. 
<Files "config.php"> 
order allow,deny 
deny from all 
</Files> 

# Sets your 403 error document 
# not absolutely essential to have, 
# or you may already have error pages defined elsewhere 
ErrorDocument 403 /forbidden403.shtml 

# No sense advertising what we are running 
ServerSignature Off 

# END Optional Settings 

# BEGIN CMSMS and Rewrite Rules 
# Make sure you have Options FollowSymLinks 
# and Allow on 

RewriteEngine On 

# Might be needed in a subdirectory 
#RewriteBase/

# URL Filtering helps stop some hack attempts 
#IF the URI contains a "http:" 
RewriteCond %{QUERY_STRING} http\: [OR] 
#OR if the URI contains a "[" 
RewriteCond %{QUERY_STRING} \[ [OR] 
#OR if the URI contains a "]" 
RewriteCond %{QUERY_STRING} \] [OR] 
#OR if the URI contains a "<script>" 
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR] 
#OR script trying to set a PHP GLOBALS variable via URL 
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR] 
#OR any script trying to modify a _REQUEST variable via URL 
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2}) 
RewriteRule ^.*$ - [F,L] 
# END Filtering 

# CMSMS Rewriting 
# Set assume mod_rewrite to true in config.php and clear CMSMS cache 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)$ /index.php?page=$1 [QSA] 
# END CMSMS 

# END Rewrite rules 

任何帮助将不胜感激。

回答

3

重写规则只需要被写入有点不同:

RewriteRule ^test.asp$ http://www.example.com/test.html [NC,R=301,L] 

这对我的作品。

+0

只是想补充一点,我有这个麻烦,直到我把301重定向在我的所有其他重定向规则的开始。这个语法虽然是最后的工作。 – 2013-10-18 21:21:57

+0

您正在改写为SEO/SEF格式,然后您需要重写为最终的“动态”格式。您必须先执行此操作,或直接将其重写为最终格式。 – 2013-12-27 18:13:48

1

请考虑使用以下规则来代替:

RewriteRule test.asp http://www.example.com/test.html [NC,R=301,L]