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重写URL_Php_.htaccess_Url Rewriting - Fatal编程技术网

Php 如何使用HTACCESS重写URL

Php 如何使用HTACCESS重写URL,php,.htaccess,url-rewriting,Php,.htaccess,Url Rewriting,这是我的htaccess文件中的一行代码 RewriteRule ^([^\.]+)$ details.php 这个URL可以正常工作 example.com/shiv-sales-corporation 现在我想在URL的末尾添加.html example.com/shiv-sales-corporation.html 我已经用这个更改了我的htaccess代码 RewriteRule ^([^\.]+)\.html$ view_details.php 但其他页面或链接冲突后,请帮助我

这是我的htaccess文件中的一行代码

RewriteRule ^([^\.]+)$ details.php
这个URL可以正常工作

example.com/shiv-sales-corporation
现在我想在URL的末尾添加.html

example.com/shiv-sales-corporation.html
我已经用这个更改了我的htaccess代码

RewriteRule ^([^\.]+)\.html$ view_details.php
但其他页面或链接冲突后,请帮助我

注意:“shiv sales corporation”是一个slug,我从数据库中获取它,它通过页面上的其他链接随机更改。示例:

example.com/ibm

example.com/apple-corp

example.com/himalaya-ltd

希望这对您有用:

RewriteRule ^([^\.]+)([\.html]*)$ view_details.php
我假设您希望在每次访问列出的URL时重定向到view_details.php。无论.html是否存在

RewriteEngine On
RewriteRule ^([^/]*)\.html$ /details.php?name=$1 [L]
其中name是来自数据库的动态参数


RewriteRule^(.*).html$$1[R=301,L]

您不能指定此名称,因为它是从数据库中随机生成的。是的,但您的代码仍然存在相同的问题。它只是配置.html并将所有html链接重定向到details.phpCheck here:它在这里工作。你也可以试试这个:
RewriteRule^([^\.]+)([\.html])*$view\u details.php
希望这个工具会有帮助:)RewriteRule([a-zA-Z0-9\+-]+)\/products\.html products.php现在这种重写规则不起作用了,所有的.html url都会去查看\u details.phpad这个规则:
RewriteRule^([^\.]+)([products\.html]*)$products.php