【问题标题】:.htaccess ampersand to question mark and remove index.php.htaccess & 符号问号并删除 index.php
【发布时间】:2014-02-15 06:56:48
【问题描述】:

我想更改网址 http://example.com/index.php?city=newyork&cat=apple&q=ipadhttp://example.com/newyork?cat=apple&q=ipad

请帮帮我。

我有 .htaccess

DirectoryIndex index.php

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^/([a-z]+)(?:$|\?(?:.+)) /index.php?city=$1 [NC,L,B,QSA,NE]

但它不起作用

【问题讨论】:

    标签: php regex apache .htaccess mod-rewrite


    【解决方案1】:

    试试这个规则:

    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([\w-]+)/?$ /index.php?city=$1 [L,QSA]
    

    【讨论】:

    • 哦,非常感谢
    • 请告诉我如果包含字符'-'怎么办?
    • 抱歉没看懂您的评论。
    【解决方案2】:
    RewriteCond %{QUERY_STRING} ^city=([^&]*)&(.*)$
    RewriteRule ^index\.php$ /%1?%2
    

    参考:http://wiki.apache.org/httpd/RewriteQueryString

    【讨论】:

      猜你喜欢
      • 2016-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-19
      • 2018-12-01
      • 2019-04-06
      • 2014-06-19
      • 1970-01-01
      相关资源
      最近更新 更多