Raj
Raj

Reputation: 1437

htaccess rewriting rules not working

I am trying to rewrite the following url

http://localhost/foldername/index.php?url=writeboard/index&step=1&id=1

to

http://localhost/foldername/writeboard/index/step/1/id/1

Code is

RewriteRule ^(.+?)(?:/(step)/([0-9]+))?/?$ index.php?url=$1&$2=$3 [NC,L,QSA]

I tried with

RewriteRule ^(.+?)(?:/(step)/([0-9]+))(?:/(id)/([0-9]+))?/?$ index.php?url=$1&$2=$3&$4=$5 [NC,L,QSA]

it works but when the url becomes http://localhost/foldername/writeboard/index then I am getting 404.

Upvotes: 1

Views: 54

Answers (2)

anubhava
anubhava

Reputation: 784898

This rule should work:

RewriteRule ^(.+?)/(step)/([0-9]+)/(id)/([0-9]+)/?$ index.php?url=$1&$2=$3&$4=$5 [NC,L,QSA]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?)/?$ index.php?url=$1 [NC,L,QSA]

Upvotes: 1

ujovlado
ujovlado

Reputation: 190

You should also add RewriteBase /foldername/ to your .htaccess file, since you're not in the top level.

More information about RewriteBase can be found here.

Upvotes: 0

Related Questions