【问题标题】:301 Redirect URLs with special characters to homepage htaccess301 将带有特殊字符的 URL 重定向到主页 htaccess
【发布时间】:2018-05-12 04:01:06
【问题描述】:

我有大约 90 个这样的网址......

www.domain.com/index.php?page=about-us
www.domain.com/index.php?page=Testimonials
www.domain.com/index.php?page=contact-us-2
www.domain.com/index.php?mact=News,cntnt01,detail,0&cntnt01articleid=184&cntnt01origid=68&cntnt01returnid=68

等等。等等

我需要对包含 /index.php 的任何 URL 执行通配符 301 重定向?到主页。我该怎么办?

谢谢

【问题讨论】:

    标签: apache .htaccess redirect mod-rewrite lamp


    【解决方案1】:

    您可以在站点根目录 .htaccess 中将此规则用作您的第一条规则

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} \s/+index\.php[?/\s] [NC]
    RewriteRule ^ /? [L,R=301]
    
    RewriteCond %{QUERY_STRING} ^(?:page|mact)= [NC]
    RewriteRule ^ /? [L,R=301]
    

    目标URI中/之后的?用于剥离index.php?之后存在的任何查询字符串

    【讨论】:

    • 它没有工作,但我不认为这是因为你的代码。出于某种原因,我的网站看起来甚至在 URL 加载之前就删除了 index.php。这是一个wordpress网站。所以 url 变成 www.domain.com/?page=contact-us-2。如果我删除 '+index\.php' 会起作用吗?谢谢
    • like so... # BEGIN WordPress RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} \s/+index\.php[?/\s] [NC] RewriteRule ^ /? [L,R=301] RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule 。 /index.php [L] # 结束 WordPress
    • 如果 URL 包含 "?page=" 和 "?mact=" 例如,我如何编辑上述 .htaccess 到 301 重定向 URL 到主页 -- 'www.domain.com?page =page-a' 和 ''www.domain.com?mact=page-a' 等等。
    • 我在回答中为此添加了一条新规则。但以后请不要通过 cmets 部分发布新要求。更喜欢针对新问题发布新问题。
    • 你可以试试最后一条规则RewriteRule !^wp-admin/ /? [L,R=301,NC]
    猜你喜欢
    • 1970-01-01
    • 2019-01-05
    • 1970-01-01
    • 2013-08-06
    • 1970-01-01
    • 1970-01-01
    • 2016-01-28
    • 2016-04-13
    • 1970-01-01
    相关资源
    最近更新 更多