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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/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 如何使用.htacces modrewrite创建更好的URL_Php_.htaccess_Url_Mod Rewrite - Fatal编程技术网

Php 如何使用.htacces modrewrite创建更好的URL

Php 如何使用.htacces modrewrite创建更好的URL,php,.htaccess,url,mod-rewrite,Php,.htaccess,Url,Mod Rewrite,这是我的网址现在我的产品 我想做到这一点 我一直在修改我的.htaccess,但实际上没有关于如何实现这一点的线索。这个问题很常见,我只是在这里用代码给出了完整的答案: 您必须将URL与模式匹配,并将其重写为目标URL RewriteRule ^/product/(\d+)- /product.php?product=$1 此模式匹配任何以/product/开头的URL,并捕获以下数字(\d+),后跟破折号-。替换URL将是/product.php?product=,并附加捕获的数字$1

这是我的网址现在我的产品

我想做到这一点


我一直在修改我的.htaccess,但实际上没有关于如何实现这一点的线索。

这个问题很常见,我只是在这里用代码给出了完整的答案:


您必须将URL与模式匹配,并将其重写为目标URL

RewriteRule ^/product/(\d+)- /product.php?product=$1
此模式匹配任何以
/product/
开头的URL,并捕获以下数字
(\d+)
,后跟破折号
-
。替换URL将是
/product.php?product=
,并附加捕获的数字
$1


要捕获匹配的某些部分,请将其括在括号中
(…)
。阅读更多关于mod_rewrite at.中使用的正则表达式的信息。

我能够使用这个RewriteRule^repuesto/([^/]+)-?$product.php?product=$1[L]实现它,但现在页面链接和图像被分离,我正在弄清楚原因。谢谢