1

I have an .htaccess file that does a lot of redirecting. A few of my redirects are not working in the mod_rewrite part. I want these redirects to work like this:

package_listing.php?package-type=fly-snooze-cruise => /fly-snooze-cruise
package_listing.php?package-type=fly-snooze-cruise&airport=orlando-airport => /fly-snooze-cruise/orlando-airport
package_listing.php?package-type=fly-snooze-cruise&airport=orlando-sanford-airport => /fly-snooze-cruise/orlando-sanford-airport
package_listing.php?package-type=fly-snooze-cruise&airport=melbourne-airport => /fly-snooze-cruise/melbourne-airport
package_listing.php?package-type=snooze-park-cruise => /snooze-park-cruise

What I've tried so far:

RewriteRule ^package_listing.php?package-type=(.*)$ /$1 [L,R=301]
RewriteRule ^package_listing.php?package-type=(.*)$&airport=(.*)$ /$1/$2 [L,R=301]


RewriteRule ^package_listing.php?package-type=([A-Za-z/]*)$ /$1 [L,R=301]
RewriteRule ^package_listing.php?package-type=([A-Za-z/]*)$&airport=([A-Za-z/]*)$ /$1/$2 [L,R=301]


RewriteRule ^package_listing.php?package-type=snooze-park-cruise$ /snooze-park-cruise [L,R=301]
RewriteRule ^package_listing.php?package-type=fly-snooze-cruise$ /fly-snooze-cruise [L,R=301]
RewriteRule ^package_listing.php?package-type=fly-snooze-cruise&airport=orlando-airport$ /fly-snooze-cruise/orlando-airport [L,R=301]
RewriteRule ^package_listing.php?package-type=fly-snooze-cruise&airport=orlando-sanford-airport$ /fly-snooze-cruise/orlando-sanford-airport [L,R=301]
RewriteRule ^package_listing.php?package-type=fly-snooze-cruise&airport=melbourne-airport$ /fly-snooze-cruise/melbourne-airport [L,R=301]

package-type and airport are both variables that determines the dynamic content in the page to be loaded.

1 Answer 1

1

You will need 2 redirect rules:

RewriteEngine On

RewriteCond %{THE_REQUEST} /package_listing\.php\?package-type=([^\s&]+)\s [NC]
RewriteRule ^ /%1? [R=302,L,NE]

RewriteCond %{THE_REQUEST} /package_listing\.php\?package-type=([^\s&]+)&airport=([^\s&]+)\s [NC]
RewriteRule ^ /%1/%2? [R=302,L,NE]
Sign up to request clarification or add additional context in comments.

2 Comments

What about the airport? I would need to add /package-type/airport for the URLs to work.
Ok, the first 4 lines works fine. The rest I don't need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.