简体   繁体   English

.htaccess 301重定向添加了一个额外的斜杠

[英].htaccess 301 redirect adds an extra slash

On a site that was once migrated from .asp to .php, I used the following in the .htaccess file to ensure users following old links would end up on the right page: 在曾经从.asp迁移到.php的站点上,我在.htaccess文件中使用了以下内容,以确保跟随旧链接的用户最终会出现在右侧页面上:

RewriteEngine On
RedirectMatch 301 (.*)\.asp$ http://www.website.org/$1.php

I just moved the site to a new server, where requests for .asp pages now end up with an extra slash in the address, immediately before the page name: 我刚刚将网站移动到一个新的服务器,其中.asp页面的请求现在最终在地址中有一个额外的斜杠,紧接在页面名称之前:

http://www.website.org//page.php

(How) can the above .htaccess code be tweaked to eliminate that extra slash? (如何)可以调整上面的.htaccess代码以消除额外的斜杠?

You're making an assumption that RewriteEngine On is needed for RedirectMatch but it is not. 您假设RedirectMatch需要RewriteEngine On ,但事实并非如此。 RedirectMatch is directive of mod_alias and other one is from mod_rewrite . RedirectMatchmod_alias指令,另一个来自mod_rewrite

You can fix your code by using either of these two code: 您可以使用以下两个代码中的任何一个来修复代码:

Option 1: 选项1:

RewriteEngine On
RewriteRule ^(.+?)\.asp$ http://www.website.org/$1.php [L,NC,R=301]

Option 2: 选项2:

RedirectMatch 301 ^/(.+?)\.asp$ http://www.website.org/$1.php

You also need to make sure to test it after clearing your browser cache or in a new browser to avoid old browser cache. 您还需要确保在清除浏览器缓存或新浏览器对其进行测试,以避免旧的浏览器缓存。

Have you tried this? 你试过这个吗?

RewriteEngine On
RedirectMatch 301 ^.*/(.*)\.asp$ http://www.website.org/$1.php

Try this way: 试试这种方式:

RewriteEngine On
RewriteRule  ^(.*)\.asp$ http://www.website.org/$1.php [NC,R=301]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM