【问题标题】:htaccess rewrite rule for subdomains with page id具有页面 id 的子域的 htaccess 重写规则
【发布时间】:2014-10-18 00:49:40
【问题描述】:

我想重定向

http://subdomain.example.com/index.php?pageID=45

http://example.com/subdomain/45.html

请帮我解决这个问题

我试过了

RewriteCond %{HTTP_HOST} ^(www\.)?subdomain\.example\.com$ [NC] RewriteCond %{REQUEST_URI} ^/$ RewriteRule ^(.*)$ http://www.example.com/sudomain/$1 [L,R=301]

【问题讨论】:

    标签: .htaccess mod-rewrite subdomain


    【解决方案1】:

    您可以在您的 htaccess 中(在根文件夹中)用此代码替换您的代码

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$ [NC]
    RewriteCond %{QUERY_STRING} ^pageID=([1-9][0-9]*)$ [NC]
    RewriteRule ^index\.php$ http://example.com/subdomain/%1.html? [R=301,L]
    

    【讨论】:

    • 代码正在运行,最后再次显示“?pageID=45”。感谢您的时间和帮助
    • 对不起,我编辑了我的答案以避免这种行为。只需在%1.html 之后添加?(见新代码)
    猜你喜欢
    • 2012-08-12
    • 2010-09-26
    • 2011-11-21
    • 2012-07-31
    • 2012-06-11
    • 2014-06-14
    • 2013-05-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多