[英]Change the .htaccess router, id to title
I am working with PHP.我正在使用 PHP。 My htaccess looks like this:
我的 htaccess 看起来像这样:
RewriteEngine On
RewriteRule ^news/([a-zA-Z0-9_-]+)(|/)$ index.php?url=news&id=$1
#Redirecciones
#Redirect 301 / /index.php
# Quickregister Rules
ErrorDocument 404 /error.php
Right now to access the news in this case the route would be this:现在在这种情况下访问新闻的路线是这样的:
http://localhost/news/3
And I want to change it to access some as follows我想改变它来访问一些如下
http://localhost/news/mi-noticia-nueva
http://localhost/news/mi-noticia-nueva/3
I have tried the following rewritrule without success:我尝试了以下重写规则但没有成功:
RewriteRule ^news/(\d+/[\w-]+)$ index.php?url=news?id=$1 [NC,L,QSA]
RewriteRule ^news/([a-zA-Z]+)?$ index.php?url=news&name=$1 [L]
RewriteRule ^news/(.*)$ index.php?url=news&name=$1 [L]
You can use this rule:您可以使用此规则:
RewriteRule ^(news)/(?:.*/)?(\d+)/?$ index.php?url=$1&id=$2 [L,QSA,NC]
This will support there URIs:这将支持那里的 URI:
/news/mi-noticia-nueva/3
/news/3
Pattern used is:使用的模式是:
^
: Start ^
: 开始(news)
: Match and group news
(news)
: 比赛和分组news
/
: Match a /
/
:匹配一个/
(?:.*/)?
: Match any test followed by a /
. /
的测试。 This is optional match(\d+)
: Match 1+ digits in capture group #2 (\d+)
:匹配捕获组 #2 中的 1+ 个数字/?$
: Match optional /
before end /?$
:匹配可选的/
在结束之前
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.