我有这个链接,可以使用并指向正确的文章:
<a href="https://www.example.com/news/21/Hello-World">Article</a>
<a href="https://www.example.com/news/Hello-World">Article</a>
Options -MultiViews
ReWriteEngine On
RewriteBase /
RewriteRule ^news/(\d+)/([\w-]+)/?$ news.php?id=$1&linkAddress=$2 [NC,L,NE]
是否可以从链接中删除 21 id,但仍使用该 id 从数据库获取变量。谢谢。
最佳答案
您能否尝试以下基于示例编写的内容。将这些网址放入 .htaccess 文件后,请确保清除浏览器缓存。另请确保此新规则高于您现有的 news.php
规则(如示例中所示)。
RewriteEngine ON
RewriteRule ^(news)/(Hello-World)/?$ $1/21/$2 [NC,L]
##Placing OP's rule to serve urls starting with news with news.php in backend.
RewriteRule ^news/(\d+)/([\w-]+)/?$ news.php?id=$1&linkAddress=$2 [NC,L,NE]
关于apache - 使用 .htaccess 删除链接地址中的 ID 号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65315344/