Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用htaccess和mod_重写更改URL_Php_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php 使用htaccess和mod_重写更改URL

Php 使用htaccess和mod_重写更改URL,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我的网址是http://www.testsite.com/cities?city=hyderabad 我想把这个换成http://www.testsite.com/hyderabad 我的htaccess中的代码是 RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] RewriteRule ^\.htacc

我的网址是http://www.testsite.com/cities?city=hyderabad

我想把这个换成http://www.testsite.com/hyderabad

我的htaccess中的代码是

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    RewriteRule ^\.htaccess$ - [F]
    RewriteCond %{REQUEST_URI} =""
    RewriteRule ^.*$ /public/index.php [NC,L]
    RewriteCond %{REQUEST_URI} !^/public/.*$
    RewriteRule ^(.*)$ /public/$1
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^/public/.*$ /public/index.php [NC,L]

问题是什么?RewriteRule上的RewriteEngine^[^/]*$/cities?city=$1[L]使用PHP路由器。这比.htaccess修改的URL要好。这是一条简单的路线。请阅读我问题的前两行。当我使用你发布的代码-@Daan时,你会明白@FDLMy url被重定向到了哪里