Forum Moderators: phranque

Message Too Old, No Replies

Url redirection not working

         

Janmejay

6:05 am on Nov 17, 2010 (gmt 0)

10+ Year Member



Hi,
I'm pretty new to Apache redirections.
I want to redirect the below urls to my index page i.e. http://www.example.com/. For the below mentioned urls I have written the redirections. Unfortunately these redirections are not working. Please any suggestions/solutions?

  • http://www.example.com/ex/results/000-test00.shtml?Airline=temp+Airlines+-+COA&FlightNumber=145&Command=ByFlightNumberGraph&x=1&y=2

Redirection Rule:
RewriteRule ^/ex/results/000-test00.shtml?Airline=temp+Airlines+-+COA&FlightNumber=145&Command=ByFlightNumberGraph&x=1&y=2 http://www.example.com/ [R=301,L]
  • http://www.example.com/ex/find/010-test00.shtml?Command=_byflightkey_&FlightKey=#*$!12.tre.temp-12345

Redirection Rule:
RewriteRule ^/ex/find/010-test00.shtml?Command=_byflightkey_&FlightKey=#*$!12.tre.temp-12345 http://www.example.com/ [R=301,L]
  • http://www.example.com/testing/loc/%5C

Redirection Rule:
RewriteRule ^/testing/loc/%5C http://www.example.com/ [R=301,L]
  • http://www.example.com/testing/'+queryStr+'

Redirection Rule:
RewriteRule ^/testing/'+queryStr+' http://www.example.com/ [R=301,L]
  • http://www.example.com/test/temp/tracker/flight_tracker_index.xsl%00

Redirection Rule:
RewriteRule ^/test/temp/tracker/flight_tracker_index.xsl%00 http://www.example.com/ [R=301,L]

  • http://www.example.com/test/temp/tracker_pack/pack_search.xsl?promotion=loc1-loc2-pack-pp&pack-offering-id=01&pack-include-components=FHC&pack-destination-city=loc3

Redirection Rule:
RewriteRule ^/test/temp/tracker_pack/pack_search.xsl?promotion=loc1-loc2-pack-pp&pack-offering-id=01&pack-include-components=FHC&pack-destination-city=loc3 http://www.example.com/ [R=301,L]
  • http://www.example.com/test/temp/flighttrack/flight_track_index.xsl?promo=55_405

Redirection Rule:
RewriteRule ^/test/temp/flighttrack/flight_track_index.xsl?promo=55_405 http://www.example.com/ [R=301,L]

keenox

3:04 pm on Nov 17, 2010 (gmt 0)

10+ Year Member



What exactly are you trying to do? Please give us some examples and some explanations, because I don't understand what you want.

At the first look, I recommend you to escape the '?','$','#','*' because they are interfering with regex.
for example:

search.xsl?promotion is interpreted by regex as any string that has 'search' in the beginning followed by any character, followed by xs, followed by 0 or 1 's' followed by promotion. This means the string
'search_xspromotion' will match your search. Please read a RegEx tutorial beforehand.

If you don't want any string matches (i.e. you only want to redirect one URL) you should use Redirect insead of RewriteRule.

jdMorgan

7:55 pm on Nov 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1) If this code goes into example.com/.htaccess or into a <Directory> container in a server config file, remove the leading slash from your RewriteRule patterns.

2) RewriteRule cannot see query strings. Move the desired-match query string pattern to a preceding RewriteCond examining the variable %{QUERY_STRING}.

3) End-anchor your patterns when possible to prevent ambiguous matches.

4) Add a "?" to the end of your substitution URL to clear the current query string.

5) As noted by keenox, all characters used as operators or quantifiers by the regular-expressions engine must be escaped by preceding them with a "\". These operators and quantifiers are listed and described in the Apache mod_rewrite documentation. A link to this documentation is available in our Apache Forum Charter.

6) Do not mix the use of mod_alias Redirect directives with mod_rewrite RewriteRule directives: Doing so can cause execution-order related problems, because directives are executed on a per-module basis, and not in the strict order that you place them in your config files. This can cause serious problems with search engines indexing internally-rewritten filepaths 'exposed' by subsequent redirects. Also, code that was previously working can be 'broken' if the module execution order is changed -- either explicitly or by an upgrade to a different server version which executes modules in a different order.

Example rule for use in www.example.com/.htaccess:

RewriteCond %{QUERY_STRING} ^Airline=temp\+Airlines\+-\+COA&FlightNumber=145&Command=ByFlightNumberGraph&x=1&y=2
RewriteRule ^ex/results/000-test00\.shtml?$ http://www.example.com/? [R=301,L]

Jim

Janmejay

6:38 am on Nov 19, 2010 (gmt 0)

10+ Year Member



Thanks Jim & keenox for t he valuable suggestions.

keenox i am trying to redirect the following urls to "http://www.example.com/". I can not modify the strings ( urls ) which i have given in this post. Without modifying the strings can i redirect them to my desired url ?

Jim i tried the pattern and able to resolve few. Still i am not being able to resolve the redirection for the following urls. Can you please guide me in this ?

* http://www.example.com/testing/loc/%5C
Redirection Rule:
RewriteRule /testing/loc/%5C http://www.example.com/? [R=301,L]

* http://www.example.com/testing/'+queryStr+'
Redirection Rule:
RewriteRule /testing/'+queryStr+' http://www.example.com/? [R=301,L]

* http://www.example.com/test/temp/tracker/flight_tracker_index.xsl%00
Redirection Rule:
RewriteRule /test/temp/tracker/flight_tracker_index.xsl%00 http://www.example.com/? [R=301,L]

* http://www.example.com/test/temp/tracker_pack/pack_search.xsl?promotion=loc1-loc2-pack-pp&pack-offering-id=01&pack-include-components=FHC&pack-destination-city=loc3
Redirection Rule:

RewriteRule /test/temp/tracker_pack/pack_search.xsl http://www.example.com/? [R=301,L]
RewriteCond %{QUERY_STRING} &?promotion=loc1-loc2-pack-pp&pack-offering-id=01&pack-include-components=FHC&pack-destination-city=loc3

* http://www.example.com/test/temp/flighttrack/flight_track_index.xsl?promo=55_405
Redirection Rule:

RewriteRule /test/temp/flighttrack/flight_track_index.xsl http://www.example.com/? [R=301,L]
RewriteCond %{QUERY_STRING} &?promo=55_405

jdMorgan

3:22 am on Nov 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteConds must go before the (single) RewriteRule that they affect.

I presume that you have read the mod_rewrite documentation cited in our Apache Forum Charter. If not, it will save you a lot of time and effort to do so.

Jim