Question

I have used the following rule for my URL rewriting. It works fine up to the second parameter. But when I use with the third parameter, it is not working. For example, I use http://example.com/1/2/3 and it is not working, but with http://example.com/1/2 it is working.

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(\w+)$ ./index.php?api=$1
RewriteRule ^([^.]+)/([0-9]+)$ index.php?api=$1&id=$2
RewriteRule ^([^.]+)/([0-9]+)/([a-zA-Z0-9]+)$ index.php?api=$1&id=$2&action=$3 
Was it helpful?

Solution 2

Try this, It worked for me.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(\w+)$ ./index.php?api=$1
RewriteRule ^(\w+)/([0-9]+)$ index.php?api=$1&id=$2
RewriteRule ^(\w+)/([0-9]+)/([a-zA-Z0-9]+)$ index.php?api=$1&id=$2&action=$3 

OTHER TIPS

This solved my problem.

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(\w+)$ ./index.php?api=$1
RewriteRule ^(\w+)/(\w+)$ index.php?api=$1&id=$2
RewriteRule ^(\w+)/(\w+)/(\w+)$ index.php?api=$1&id=$2&action=$3 
RewriteRule ^(\w+)/(\w+)/(\w+)/(\w+)$ index.php?api=$1&id=$2&action=$3&k=$4 
RewriteRule ^(\w+)/(\w+)/(\w+)/(\w+)/(.*)$ index.php?api=$1&id=$2&action=$3&k=$4&v=$5 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top