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从website.com重定向/?u=1&;name=john to website.com/1/john_Php_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php htaccess从website.com重定向/?u=1&;name=john to website.com/1/john

Php htaccess从website.com重定向/?u=1&;name=john to website.com/1/john,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,找到了这个,但是我想查询字符串 RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} \s/+profile\.php\?u=([^\s&]+) [NC] RewriteRule ^ /%1? [R=302,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/?$ profile.ph

找到了这个,但是我想查询字符串

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+profile\.php\?u=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]

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

为2个参数添加新的重定向和重写规则:

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+profile\.php\?u=([^\s&]+)&name=([^\s&]+) [NC]
RewriteRule ^ /%1/%2? [R=302,L]

RewriteCond %{THE_REQUEST} \s/+profile\.php\?u=([^\s&]+)\s [NC]
RewriteRule ^ /%1? [R=302,L]

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/([^/]+)/?$ profile.php?u=$1&name=$2 [L,QSA]

RewriteRule ^([^/]+)/?$ profile.php?u=$1 [L,QSA]

好的,这确实重定向到了website.com/1/john,但是控制器无法识别它,我们还能在服务器上使用profile.php吗?php?u=$1&name=$2让php理解吗?这个新的重写规则
RewriteRule^([^/]+)/([^/]+)/?$profile.php?u=$1&name=$2[L,QSA]
实际上是在内部实现的
profile.php?u=$1&name=$2