I am using PHP for my work. My htaccess file is as follows:
RewriteEngine On RewriteRule ^news/([a-zA-Z0-9_-]+)(|/)$ index.php?url=news&id= #Redirecciones #Redirect 301 / /index.php # Quickregister Rules ErrorDocument 404 /error.php
Now, to access the news, the routing should look like this:
http://localhost/news/3
I want to change access to the following method:
http://localhost/news/mi-noticia-nueva http://localhost/news/mi-noticia-nueva/3
I tried the following rewrite rules without success:
RewriteRule ^news/(\d+/[\w-]+)$ index.php?url=news?id= [NC,L,QSA] RewriteRule ^news/([a-zA-Z]+)?$ index.php?url=news&name= [L] RewriteRule ^news/(.*)$ index.php?url=news&name= [L]
You can use the following rules:
This will support the following URIs:
The mode used is:
^
:Start(news)
: Match and groupnews
/
:match/
(?:.*/)?
: Matches any text followed by/
. This is an optional match(\d )
: Match 1 or more digits in capturing group #2/?$
: Matches optional/