首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >由于URL重写导致的301重定向问题

由于URL重写导致的301重定向问题
EN

Stack Overflow用户
提问于 2010-02-02 18:35:02
回答 2查看 2K关注 0票数 1

我有一个新的网站设置使用CMSMadeSimple (基于PHP),但我有问题301重定向旧网站的网址与新的设置。

我使用的是一个标准的.htaccess文件的内容管理系统,翻译搜索引擎友好的网址,如http://www.example.com/test.htmlhttp://www.example.com?page=test,但我也需要重定向旧网址(ASP网站)在这个文件。

我当前的.htaccess如下所示,我尝试添加的代码行是

代码语言:javascript
复制
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

代码语言:javascript
复制
# 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

任何帮助都将不胜感激。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-03-06 00:48:39

重写规则只需要稍微改变一下:

代码语言:javascript
复制
RewriteRule ^test.asp$ http://www.example.com/test.html [NC,R=301,L]

这对我很有效。

票数 3
EN

Stack Overflow用户

发布于 2010-02-03 00:00:16

请考虑改用以下规则:

代码语言:javascript
复制
RewriteRule test.asp http://www.example.com/test.html [NC,R=301,L]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2183326

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档