Search code examples
.htaccessurlmod-rewriteurl-rewritingfriendly-url

Make SEO Friendly URL in Php with help of .htaccess


I want to make my URL from this:
https://www.website.com/index.php?title=A1-13-05-2021

to this:
https://www.website.com/A1-13-05-2021

And want to access above query string param in index.php as $_GET['title'].

For this, I have written the below .htaccess code. But that's not working

RewriteEngine On
RewriteRule ^index?$ index.php

RewriteRule ^index/([a-zA-Z0-9\-]+) index.php?title=$1

Can anyone please help me to know where I am doing wrong?

Thanks.


Solution

  • With your shown samples, could you please try following. Please make sure to clear your browser cache before testing your URLs.

    RewriteEngine ON
    ##Rule for handling non-existing pages here to index.php file.
    RewriteRule ^(A1-13-05-2021)/?$ index.php?title=$1 [QSA,NC,L]
    


    Generic Rules: In case you want to make it Generic rules then try following rules only.

    RewriteEngine ON
    ##Rule for handling non-existing pages here to index.php file.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(A1-\d{2}-\d{2}-\d{4})/?$ index.php?title=$1 [QSA,NC,L]