使用具有双正斜杠的URL设置301重定向

时间:2016-08-17 16:43:32

标签: apache .htaccess redirect mod-rewrite

帮助!我正在尝试设置我的URL http://www.sample.com/blog//press_releases.php以重定向到/,我已经尝试在SEO中输入它,将/blog//press_releases.php添加到/并且它不起作用。还尝试输入我的.htaccess,但似乎没有任何工作使用以下内容:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/([^/]+)//+(.*)$
RewriteRule // https://www.sample.com/%1/%2 [R=301,L] 

我的.htaccess文件中存在此内容:

    Redirect 301 /upcoming-events-iaug-converge-2013-and-telematics-detroit /blog/upcoming-events-iaug-converge-2013-and-telematics-detr‌​oit/
    Redirect 301 /can-you-identify-with-me /blog/can-you-identify-with-me/ 
    Redirect 301 /speech-recognition-success-or-failure-is-not-always-black-o‌​r-white /blog/speech-recognition-success-or-failure-is-not-always-bl‌​ack-or-white/ 
    Redirect 301 /transforming-a-contact-center-father /blog/transforming-a-contact-center-father/ 
    Redirect 301 /the-fifth-game-jinx /blog/the-fifth-game-jinx/

1 个答案:

答案 0 :(得分:0)

您可以在站点根.htaccess中使用此规则来删除所有多个斜杠:

RewriteEngine On

RewriteCond %{THE_REQUEST} //
RewriteRule ^.*$ /$0 [R=301,L,NE]