Amit Singh
Amit Singh

Reputation: 2275

Rewrite-dynamic URL .htaccess

I am trying to re-write the dynamically generated URL. But the rules i have written is not affecting the URL even a single bit.

The URL currently shows up like: http://ukfurniturespecialist.co.uk/county.php?c=Oxfordshire&%20t=Faringdon

And i would like it to look like: http://ukfurniturespecialist.co.uk/county-c-Oxfordshire-t-Faringdon.html

This is what i have tried:

Options +FollowSymLinks
RewriteEngine on
RewriteRule county-c-(.*)-%20t-(.*)\.html$ county.php?c=$1&%20t=$2

Any help is much appreciated,Thanks.

Upvotes: 1

Views: 112

Answers (2)

anubhava
anubhava

Reputation: 784958

For your URL following rule should work:

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+county\.php\?c=([^&]*)&.*?t=([^&\s]*) [NC]
RewriteRule ^ county-c-%1-t-%2.html? [R=302,L]

RewriteRule ^county-c-([^-]+)-t-([^.]+)\.html$ county.php?c=$1&\%20t=$2 [L,QSA,NE]

Upvotes: 1

ZubaiR
ZubaiR

Reputation: 605

%20 represents a space character in url. when writing rewrite rule the url is already decoded and handled using "\ " instead of %20

For your URL the rewrite rule should be

Options +FollowSymLinks
RewriteEngine on
RewriteRule county-c-(.*)-\ t-(.*)\.html$ county.php?c=$1&\ t=$2

I dont think you need to put space character in your url. If you remove the %20 from your URL the rewrite rule should be

RewriteRule county-c-(.*)-t-(.*)\.html$ county.php?c=$1&t=$2

Upvotes: 1

Related Questions