5

The below are all my .htaccess entry:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.acethehimalaya\.com$ [NC]
RewriteRule (.*) http://www.acethehimalaya.com/$1 [R=301,L]

redirect 301 /brochure_request.php http://www.acethehimalaya.com/request-brochures.html
redirect 301 /testimonials.php http://www.acethehimalaya.com/testimonials.html

RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.acethehimalaya.com/$1 [R=301,L]

But the last entry for redirecting:

http://www.acethehimalaya.com/tripdetails.php?trip_id=8   

to

http://www.acethehimalaya.com/destinations/nepal/nepal-trekking/everest-base-camp-budget-trek.html

is not working. The code i have used is below:

RewriteCond   %{REQUEST_URI}    ^/tripdetails.php$
RewriteCond   %{QUERY_STRING}   ^trip_id=8$
RewriteRule   ^(.*)$ http://www.acethehimalaya.com/destinations/nepal/nepal-trekking/everest-base-camp-budget-trek.html  [R=301,L]

Its been like days and i m struck so can anybody figure this out.

1
  • The server is currently issuing a 301 redirect for that URL, except the Location: HTTP response header is blank?!
    – MrWhite
    Commented Jan 29, 2013 at 19:26

2 Answers 2

1

Why not use a simple Redirect 301?

Redirect 301 /tripdetails.php?trip_id=8    http://www.acethehimalaya.com/destinations/nepal/nepal-trekking/everest-base-camp-budget-trek.html
2
  • The edit has already been made by @Stephen, but I think it's worth mentioning... the URL-path (2nd argument to the Redirect directive) should be a root-relative path (beginning with a slash), not an absolute URL.
    – MrWhite
    Commented Jan 29, 2013 at 22:18
  • I tried the simple redirect but it dint work so i thought it was because of string variable URl Commented Jan 30, 2013 at 4:36
0

You've already been given a working solution (see @puppybeard post), but just to clear things out and answer why your redirect rules didn't work:

What you've done is ended your conditional strings with a dollar sign $ that signals to the redirect engine parser that the string sought should end exactly with whatever preceded the $ sign. The opposite to $ is ^ sign that signals the string sought should start with whatever follows this sign. Since you put ^/tripdetails.php$ between both 'starts with' ^ and 'ends with' $ the only URI that would match it is '/tripdetails.php' itself. Since QUERY_STRING is a part of REQUEST_URI, this wouldn't work. However, even if that exact URI was used, it wouldn't redirect due to another rule following it that would only match the query part of the URI ^trip_id=8$ (or exactly 'trip_id=8'). They're two mutually exclusive sets of rules. If you prefer redirecting with rewrite conditions, then your code would look like:

RewriteEngine On 
RewriteCond   %{REQUEST_URI}    ^/tripdetails.php [NC]
RewriteCond   %{QUERY_STRING}   trip_id=8(&|$) [NC]
RewriteRule   ^(.*)$ http://www.acethehimalaya.com/destinations/nepal/nepal-trekking/everest-base-camp-budget-trek.html  [R=301,L]

I've added NC (no-case) flag so the rule also supports same URIs that were typed with (some or all) capital characters.

If it doesn't matter to you which solution you use, then better use the one provided by @puppybeard as it's more straight-forward and easier to control. Note though, Redirect directive is case-sensitive.

Cheers!

3
  • I used both the solution but it doesnt get redirected and i m in mess already :(( Commented Jan 30, 2013 at 4:40
  • I have been posting this questions for couple of days now and changed many entries..everyone suggesting me the code says it works for them but the problem is it doesnt work for me. The other entries i have used are working so i guess my RewriteEngine is on...i dont have much knowledge on this issue and my web developers are not working on it...i m just frustrated you know :(( Commented Jan 30, 2013 at 4:52
  • I have got so many questions now....confused like anything! Commented Jan 30, 2013 at 5:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.