I'm trying to rewrite this:




Using this Rewrite Rule

RewriteEngine on
RewriteRule ^article/([0-9]+)/([0-9a-zA-Z_-]+)$ article.html?id=$1&title=$2 [NC,L] 

However, when I try this code in https://htaccess.madewithlove.com/ it gives me

This rule was not met.

Also tried it on my website htaccess file with no result. I don't know where is the problem.

1 Answer 1


from stackoverflow

Using this in htaccess:

RewriteEngine ON
##External redirect in browser rules here....
RewriteCond %{THE_REQUEST} \s/([^/]*)/([^.]*)\.html\?id=([^&]*)&title=(\S+)\s [NC]
RewriteRule ^ /%1/%2/%3/%4? [R=301,L]

##Internal rewrite to html file rules here....
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/?$  $1/$2.html?id=$3&title=$4 [QSA,NC,L]

and this in article.html right after head opening tag

<base href="/" /> 

All is working as intended. Someone helped me with that code :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.