rns
rns

Reputation: 92

RewriteRule redirects to unexpected page

I am trying to change my url through .htaccess in the following way

Original URL: http://www.example.com/latest-news.php?id=2/topic=testing
Rewritten URL:http://www.example.com/2/testing
Rule for .htaccess
RewriteRule ^([^/]*)/([^/]*)$ /latest-news.php?id=$1&topic=$2 [L]

This is working fine but the other files which are existing in a folder are not opening. The url is opening as www.example.com/testing/foo.php but content of the page is of http://www.example.com/2/testing

Upvotes: 0

Views: 21

Answers (2)

rns
rns

Reputation: 92

RewriteEngine On
RewriteRule ^([0-9]+)/([^/]*)$  /latest-news.php?id=$1&url=$2 [L]

Since second part consists characters and digits So I modify the answer of stoica. Thanks @stoica

Upvotes: 0

Bogdan Stoica
Bogdan Stoica

Reputation: 4539

Can you try with a similar rule like the one bellow?

RewriteRule ^([0-9]+)/([a-zA-Z])$ /latest-news.php?id=$1&topic=$2 [L]

Can't really test it on my server but you can adapt it to suit your needs

Upvotes: 1

Related Questions