demogorgorn
demogorgorn

Reputation: 324

Apache .htaccess redirect do not find match in url when script is in subfolder

I have an url like "http://www.example.com/mobiles/page.php?id=999". I want to redirect all requests on urls like this on to new ones like "http://www.example.com/mobiles/page/show/999".

I wrote .htaccess in mobiles subfolder:

Options +FollowSymLinks
IndexIgnore */*

RewriteEngine on

RewriteCond %{THE_REQUEST} \s/page\.php\?id=([0-9]+)\s [NC]
RewriteRule ^ /page/show/%1? [R=301,L]

But the match does not fire. What the problem is? Thanks in advance!

update:

I'm having big difficulties to write htaccess regexp which matches "page.php?id=" in url like this "http://www.example.com/mobiles/page.php?id=999". I've checked the online htaccess testers but anything really helps...

Upvotes: 1

Views: 91

Answers (3)

Amit Verma
Amit Verma

Reputation: 41219

There is a slight typo in your RewriteCond. You forgot to add your dir name to the pattern.

RewriteCond %{THE_REQUEST} /mobiles/page\.php\?id=([0-9]+) [NC]

Upvotes: 1

Joe
Joe

Reputation: 4917

This should do it:

RewriteEngine On
RewriteRule ^mobiles/page/show/([^/]*)$ /mobiles/page.php?id=$1 [L]

Just make sure you clear your cache before testing this.

Upvotes: 1

alexqinbj
alexqinbj

Reputation: 1251

It seems RewriteRule is not complete, move the match pattern from RewriteCond to RewriteRule, an example like this.

RewriteRule    ^products/([0-9]+)/?$    show_a_product.php?product_id=$1    [NC,L] 

Upvotes: 0

Related Questions