由于URL重写导致301重定向问题(Problem with 301 redirects due to URL rewriting)

编程入门 行业动态 更新时间:2024-10-28 16:30:47
由于URL重写导致301重定向问题(Problem with 301 redirects due to URL rewriting)

我使用CMSMadeSimple(基于PHP)进行了新的站点设置,但是我遇到了问题301使用新设置重定向旧站点URL。

我正在使用CMS的标准.htaccess文件,它将SEO友好的URL(如http://www.example.com/test.html)转换为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

任何帮助将不胜感激。

I've got a new site setup using CMSMadeSimple (PHP based) but I'm having problems 301 redirecting the old site URLs with the new setup.

I'm using a standard .htaccess file for the CMS which translates SEO friendly URLs like http://www.example.com/test.html into http://www.example.com?page=test, but I also need to redirect old URLs (ASP site) in this file.

My current .htaccess is shown below, the line I've tried to add is

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

but when I do this the page redirects to http://www.example.com/test.html?page=test.asp not http://www.example.com/test.html as required

# 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

Any help would be greatly appreciated.

最满意答案

重写规则只需要写一点不同:

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

这对我行得通。

The rewrite rule just needs to be written a little differently:

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

That works for me.

更多推荐

本文发布于:2023-08-04 04:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1410230.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   重定向   URL   rewriting   due

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!