HTACCESS RewriteRule
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

I'm looking for assistance with rewriting part of a URL in our .htaccess file. We have an IIS 6 configuration with IISModReWrite installed.

http://www.domain.com/private-jet-airports/airports-by-state/params/state/{STATE NAME}/

needs to redirect generically to

http://www.domain.com/private-jet-airports/US/{STATE NAME}/

We would like the redirect to be a 301 status, please.

Thank you for your help!

awarded to alv-c
Tags
-htaccess

Crowdsource coding tasks.

2 Solutions


Proper IIS Mod-Rewrite syntax:

RewriteEngine on  
RewriteRule ^private-jet-airports/airports-by-state/params/state/([A-Za-z_-]+)/?$ private-jet-airports/US/$1/ [R=301,L]

/? in Regex will force trailing slash to be optional. Just in case ;)

it worked with the addition of the base URL just as the one from @alv-c
jlevey almost 4 years ago
the first was simpler, It had a wild card (.*) instead of ([A-Za-z_-]+)
jlevey almost 4 years ago
The $1 had to be changed to $2 but that has to do with the way our rules are written
jlevey almost 4 years ago
The /? was not needed, in windows, no extension in the last bit of a url is treated as a directory it would work either way.
jlevey almost 4 years ago
Winning solution

I think this would work fine

Options +FollowSymLinks

RewriteEngine on

RewriteRule private-jet-airports/airports-by-state/params/state/(.*) private-jet-airports/US/$1 [R=301,L]

If doesn't work try adding the site domain to both url

I had to modify it to include the full URL, but it seems to be working now.
jlevey almost 4 years ago
The $1 had to be changed to $2 but that has to do with the way our rules are written
jlevey almost 4 years ago
View Timeline