Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 766
Kelly Avatar asked Dec 19 '25 10:12

Kelly


1 Answers

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]
like image 65
RavinderSingh13 Avatar answered Dec 21 '25 05:12

RavinderSingh13



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!