【问题标题】:Remove page id from url with mod_rewrite使用 mod_rewrite 从 url 中删除页面 id
【发布时间】:2016-03-05 09:07:00
【问题描述】:

我想从www.site.com/page.php?url=string.html转到www.site.com/string.html

我的 .htaccess 看起来像这样:

RewriteEngine On

RewriteRule ^([a-zA-Z0-9-/]+).html$ page.php?url=$1
RewriteRule ^([a-zA-Z0-9-/]+).html/$ page.php?url=$1

但它什么也没做。

【问题讨论】:

    标签: regex apache mod-rewrite url-rewriting friendly-url


    【解决方案1】:

    尝试以下重写:

    RewriteEngine On
    RewriteCond %{THE_REQUEST} ^GET\ /cms/page\.php\?url=([^\s&]+) [NC]
    RewriteRule ^page\.php$ /%1? [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^.*\.html$ /cms/page.php?url=$0 [QSA,L]
    

    编辑

    由于页面位于/cms 目录中,因此更新了规则以反映相同。

    【讨论】:

    • 还是什么都不做。可能是因为我在子域上测试它吗? - 测试域为:subdomain.site.com/cms/page.php?url=string.html
    • 你先生!你拯救了我的一天,非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-09
    • 1970-01-01
    • 2017-02-15
    • 2012-03-24
    • 2017-04-30
    相关资源
    最近更新 更多