I’m trying to make SEO Friendly url by altering php parameters with slash based url.
I want to make
mysite.com/TopList.php?tl=ToplistName&fr=2021-02-10&to=2021-02-20
into:
mysite.com/ToplistName/2021-02-20/2021-02-20
I had success with rewriting url but none of my includes are referring to right directory path and I get no css, js and file paths are broken from links.
This is what I have in .htaccess file now:
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)?$ TopList.php?tl=$1&fr=$2&to=$3
Anyone that can help me get this sorted out inside .htaccess file?
2
Answers
I solved this by doing following:
added to html:
<base href="http://example.com/">
added to .htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
#1 Changing Full query
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/?$ TopList.php?tl=$1&fr=$2&to=$3
#2 Changing only first landing page
RewriteRule ^([^/.]+)/?$ TopList.php?tl=$1
this gave me following result:
mysite.com/TopList.php?tl=ToplistName ==> mysite.com/ToplistName
mysite.com/TopList.php?tl=ToplistName&fr=2021-02-10&to=2021-02-20 ==> mysite.com/ToplistName/2021-02-10/2021-02-20
Based on your shown samples, could you please try following.
Please make sure you clear your browser cache before testing your URLs.