Mobile app version of vmapp.org
Login or Join
Sarah324

: My .htaccess entry is not working The below are all my .htaccess entry: RewriteEngine on RewriteCond %{HTTP_HOST} !^www.acethehimalaya.com$ [NC] RewriteRule (.*) http://www.acethehimalaya.com/

@Sarah324

Posted in: #Htaccess

The below are all my .htaccess entry:

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

redirect 301 /brochure_request.php www.acethehimalaya.com/request-brochures.html redirect 301 /testimonials.php www.acethehimalaya.com/testimonials.html
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ www.acethehimalaya.com/ [R=301,L]


But the last entry for redirecting:
www.acethehimalaya.com/tripdetails.php?trip_id=8


to
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 ^(.*)$ 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.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Sarah324

2 Comments

Sorted by latest first Latest Oldest Best

 

@Hamm4606531

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 ^(.*)$ 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!

10% popularity Vote Up Vote Down


 

@Nimeshi995

Why not use a simple Redirect 301?

Redirect 301 /tripdetails.php?trip_id=8 www.acethehimalaya.com/destinations/nepal/nepal-trekking/everest-base-camp-budget-trek.html

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme