.htaccess&符号到问号并删除index.php

时间:2014-01-24 10:16:12

标签: php regex apache .htaccess mod-rewrite

我想要更改网址 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]

但它不起作用

2 个答案:

答案 0 :(得分:3)

尝试此规则:

RewriteEngine On

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

答案 1 :(得分:0)

RewriteCond %{QUERY_STRING} ^city=([^&]*)&(.*)$
RewriteRule ^index\.php$ /%1?%2

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