Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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更改url结构_Php_Regex_Apache_.htaccess - Fatal编程技术网

Php 如何使用htaccess更改url结构

Php 如何使用htaccess更改url结构,php,regex,apache,.htaccess,Php,Regex,Apache,.htaccess,我有一个urlmyurl.com/index.php?hello=folder/7f6c06 我想将其更改为myurl.com/folder/7f6c06 我试过了 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)/?$ index.php?hello=$1 [QSA,

我有一个url
myurl.com/index.php?hello=folder/7f6c06

我想将其更改为
myurl.com/folder/7f6c06

我试过了

       RewriteEngine On

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

在godaddy主机中不工作

它不起作用,因为您的模式
([^/]+)
捕获了第一个
/
之前的所有内容,但您希望捕获并传递到
hello=
的URI本身包含一个
/
。由于在第一个
/
之后有额外的字符,但是模式在末尾最多匹配一个
/
,因此模式永远不会匹配

相反,只需使用
(.+)/?
捕获所有内容,直到可选的尾部斜杠

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