【问题标题】:Rewrite URL with multiple unset query parameters .htaccess使用多个未设置的查询参数重写 URL .htaccess
【发布时间】:2017-01-24 14:51:49
【问题描述】:

我已经阅读了很多关于使用多个参数进行 URL 重写的问题。但是我仍然无法解决这个问题:

我有这个带有多个参数的 URL,其中一些没有值
http://localhost:8888/coches/index.php?maker=all&model=&registration_year=&price_until=&tfseekfid=main_search&s=~

我想改写成http://localhost:8888/coches/all-cars

我已经尝试过这条规则和其他几个规则,但无法让它发挥作用。

RewriteRule ^all-cars$ /index.php?maker=all&model=&registration_year=&price_until=&tfseekfid=main_search&s=~ [L,QSA]

有人可以帮忙吗?谢谢

【问题讨论】:

    标签: php apache .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    包含此规则的.htaccess 文件的位置很重要。您可以在子目录中有.htaccess 文件。

    如果 .htaccess 文件在您的 docroot 中,您需要在规则中指定目录:

    <IfModule mod_rewrite.c>
    RewriteEngine on
    
    RewriteRule ^coches/all-cars$ /coches/index.php?maker=all&model=&registration_year=&price_until=&tfseekfid=main_search&s=~ [L,QSA]
    </IfModule>
    

    如果文件是/coches/.htaccess,请从规则中删除前导/,使其相对于子目录:

    <IfModule mod_rewrite.c>
    RewriteEngine on
    
    RewriteRule ^all-cars$ index.php?maker=all&model=&registration_year=&price_until=&tfseekfid=main_search&s=~ [L,QSA]
    </IfModule>
    

    【讨论】:

    • 感谢您的回答。我的路径是 /coches/.htaccess 我已经尝试了你的两个建议,但不幸的是它们都没有奏效
    • @Santos,你在 Apache 中启用了mod_rewrite 吗?
    • 是的,Apache 重写已启用
    • @Santos,您是否为本地环境配置了 AllowOverride All
    • 这是我的 MAMP Apache httpd.conf 文件 &lt;Directory /&gt; Options Indexes FollowSymLinks AllowOverride All &lt;/Directory&gt; @labue 这是我的 .htaccess 文件的内容,我正在使用 wordpress,以防它有什么不同。 RewriteEngine On RewriteBase /coches/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule 。 /coches/index.php [L] RewriteRule ^tipo/(.*) vehicle_type/$1
    猜你喜欢
    • 1970-01-01
    • 2016-02-27
    • 2013-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多