Php 如何使用htaccess更改url结构
我有一个urlPhp 如何使用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,
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]