I wanted to make seo-friendly URLs, but I have some problems while setting up the .htaccess file. First of all, I’ve made it possible to get rid of file extension (.php) and the link shows properly.
example.com/pond.php
=> example.com/pond
The problem begins when I try to add $_GET variables to the link.
What works for me is either example.com/pond.php?a=1&b=2
or example.com/pond?a=1&b=2
.
What I would like to achieve is example.com/pond-1-2
, but when I go to this link I get site not found
My .htacess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
#extension removed
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
#RewriteRule ^pond/([0-9]+)/([0-9a-zA-Z_-]+) pond.php?id=$1&name=$2 [NC,L]
#RewriteRule ^pond-(.*)-(.*)$ pond.php?id=$1&name=$2 [NC,L]
RewriteRule ^pond-([^.]+)-([^.]+)$ pond.php?id=$1&name=$2 [NC,L]
The commented rules are what I’ve tried previously, but none of these work for me. I’ve tried solutions from many topics on stackoverflow, but these also do not work for me :(.
2
Answers
RewriteRule ^(.*)-(.*)$ $1.php?id=$2 [NC,L]
This was the solution to my problem.I prepared 3 different examples. I hope it helps you or others.
Version 1:
Test
Version 2:
Test
Version 3:
Test