Redirect Loop issue for Rewrite and Redirect to same page

Helicon Ape provides support for Apache .htacces and .htpasswd configuration files for Microsoft IIS.
User avatar
Posts: 2
Joined: 03 Mar 2016, 22:52

Redirect Loop issue for Rewrite and Redirect to same page

03 Mar 2016, 23:46

I am trialling the effects of a URL rewrite on one version of one of our pages. Goal 1 does work but adding in Goal 2 creates a redirect loop. Any ideas on how this can be achieved?


GOAL 1: Rewrite (DONE)
Setup http://www.cleancruising.com.au/cruisel ... rica-line/ as a rewrite of http://www.cleancruising.com.au/cruiseline.asp?id=HAL



GOAL 2: Redirect
301 Redirect ALL traffic from http://www.cleancruising.com.au/cruiseline.asp?id=HAL over to the new page at http://www.cleancruising.com.au/cruisel ... rica-line/



CURRENT CODE:
# Helicon Ape version 3.1.0.248

RewriteEngine On
RewriteBase /
RewriteRule ^cruiseline/holland-america-line/ /cruiseline.asp?id=HAL [NC, L]

RewriteCond %{QUERY_STRING} ^id=HAL
RewriteRule ^cruiseline\.asp$ /cruiseline/holland-america-line/? [NC,R=301]

User avatar
Posts: 402
Joined: 06 Mar 2012, 11:59

Re: Redirect Loop issue for Rewrite and Redirect to same pag

04 Mar 2016, 10:24

Hello.

Add an NS flag to redirect rule to prevent from calling it on subrequests:

RewriteCond %{QUERY_STRING} ^id=HAL
RewriteRule ^cruiseline\.asp$ /cruiseline/holland-america-line/? [NS,NC,R=301]

User avatar
Posts: 2
Joined: 03 Mar 2016, 22:52

Re: Redirect Loop issue for Rewrite and Redirect to same pag

07 Mar 2016, 00:37

Yaroslav. You are fantastic.

This worked a treat. Well done. Really appreciate this as I was completely unaware of the NS flag. I will read up on the documentation.

THANK YOU!

User avatar
Posts: 402
Joined: 06 Mar 2012, 11:59

Re: Redirect Loop issue for Rewrite and Redirect to same pag

07 Mar 2016, 07:30

You're welcome!

This is to comply with Apache mod_rewrite behavior - every time config results into a change of URL, new internal subrequest is called starting all rules sequence with new URL again. This can result in a loop if one rule takes the same pattern that other generates, which is sometimes useful, but need to be screened out with NS flag when undesired.

Return to Helicon Ape

Who is online

Users browsing this forum: No registered users and 25 guests