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/8/.htaccess/6.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:$\u从URL友好的HTACCESS获取变量_Php_.htaccess_Url Rewriting - Fatal编程技术网

Php .HTACCESS:$\u从URL友好的HTACCESS获取变量

Php .HTACCESS:$\u从URL友好的HTACCESS获取变量,php,.htaccess,url-rewriting,Php,.htaccess,Url Rewriting,在我发现的一个网站中,他们使用如下友好URL: 真实网址: example.com/index.php?mode=product 友好URL example.com/view/product.html 在友好的URL中,有一个使用$\u get函数获取变量的功能。因此,如果URL如下所示: 友好URL 2 example.com/view/product.html?id=10&lang=en&cur=1 这类似于友好的URL,但允许我轻松访问可变参数 有人能帮我写一个这样的.htaccess重写

在我发现的一个网站中,他们使用如下友好URL:

真实网址:

example.com/index.php?mode=product

友好URL

example.com/view/product.html

在友好的URL中,有一个使用$\u get函数获取变量的功能。因此,如果URL如下所示:

友好URL 2

example.com/view/product.html?id=10&lang=en&cur=1

这类似于友好的URL,但允许我轻松访问可变参数


有人能帮我写一个这样的.htaccess重写规则吗

mod_rewrite中的[QSA]指令是您的朋友。它会将所有其他查询字符串参数附加到重写url的末尾:

Options +FollowSymlinks
RewriteEngine On
RewriteRule ^view/(.*).html /index.php?mode=$1 [QSA]

这是未经测试的,但只是一个快速的答案,应该可以让您继续。

mod_rewrite中的[QSA]指令是您的朋友。它会将所有其他查询字符串参数附加到重写url的末尾:

Options +FollowSymlinks
RewriteEngine On
RewriteRule ^view/(.*).html /index.php?mode=$1 [QSA]
这是未经测试的,但只是一个快速的答案,应该可以让您继续。

这个(.*)可能有点太贪婪,但这是基本的想法。(.*)可能有点太贪婪,但这是基本的想法。