Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.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中将动态url转换为静态url_Php_.htaccess - Fatal编程技术网

如何在php中将动态url转换为静态url

如何在php中将动态url转换为静态url,php,.htaccess,Php,.htaccess,我想在使用.haccess时将我的动态URL链接更改为静态URL链接,显示错误为500,我有很多不同URL链接名称的链接 Options +FollowSymLinks RewriteEngine on RewriteRule product/categoryid/(.*)/productid/(.*)/ product.php?categoryid=$1&productid=$2 RewriteRule product/categoryid/(.*)/productid/(

我想在使用.haccess时将我的动态URL链接更改为静态URL链接,显示错误为500,我有很多不同URL链接名称的链接

 Options +FollowSymLinks 
 RewriteEngine on 
 RewriteRule product/categoryid/(.*)/productid/(.*)/ product.php?categoryid=$1&productid=$2
 RewriteRule product/categoryid/(.*)/productid/(.*) product.php?categoryid=$1&productid=$2

根据您的问题,假设您是从域根运行的。因此,请将以下内容放入
/.htaccess
文件中:

Options +FollowSymLinks 

RewriteEngine On
RewriteRule ^product/categoryid/(\d+)/productid/(\d+)/?$ /product.php?categoryid=$1&productid=$2 [NC,QSA,L]
所做的更改:

  • 我已经将您的两条规则压缩为一条规则(),使结尾的正斜杠(
    /
    )成为可选的
  • 匹配表达式的开头(
    ^
    )和结尾(
    $
  • (.*)
    现在是仅与数字匹配的
    (\d+)
    (假定为ID)
  • 在规则中添加了无大小写(
    NC
    ),查询字符串附加(
    QSA
    )和最后(
    L
    )标志

  • 注意:您需要确保确实启用了
    mod\u rewrite
    。如果500内部服务器错误仍然存在,请检查您的Apache日志。

    检查服务器的错误日志以了解有关500的详细信息。问题的标题表示您正在寻找php解决方案。是否有其他方法将动态url更改为静态url,因为.htaccess无法正常工作正如我在回答中所说,请检查您的日志-那里应该有一个错误来告诉您出了什么问题。