homepage Welcome to WebmasterWorld Guest from 54.237.98.229
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Internal rewrite rule causing 302 temporary redirect response in logs.
MarkOly



 
Msg#: 4640634 posted 2:27 am on Jan 28, 2014 (gmt 0)

I noticed in my logs that one of my rewrite rules is causing the target page to return a 302 response every time it's called. This is the rule:

# Internally rewrite specific Miva Merchant pages
RewriteRule ^order/specials$ http://www.example.com/mm5/merchant.mvc?Screen=SPECIALS [L]

Miva Merchant is the shopping cart. It's a static website, except for the Miva Merchant checkout pages. This one Specials page is also a dynamic Miva Merchant page, that appears as a static page to the user as: order/specials. When this page is called, it is then internally rewritten to the correct Miva Merchant page, as seen in the rule above.

I'm guessing that the 302 has to do with the fact that I don't end the rule with "R=301". But I can't do that because I don't want to do an external redirect. What makes it confusing to me is that I'm also using an internal rewrite rule to rewrite all my extensionless urls to the correct .htm pages. Yet that rule isn't causing 302's. (I posted about extensionless url rules last June: [webmasterworld.com...] I'm sure you guys remember :)) Here's that rule:

# Internally rewrite extensionless URL requests to .htm file
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^.]+[^./]\ HTTP/
RewriteRule ^([^.]+[^./])$ /$1.htm [L]

This rule doesn’t cause 302's, but the first rule does. Any ideas on why? Is there something really simple that I'm missing?

Thanks!
MarkOly

 

not2easy

WebmasterWorld Administrator 5+ Year Member Top Contributors Of The Month



 
Msg#: 4640634 posted 2:47 am on Jan 28, 2014 (gmt 0)

Quick note on my way out -
That [L] (last) ends the process and does not specify a 301, so it defaults to 302 (Temporary) status. There is more to this, but I have to be somewhere else now, sorry. Someone will be along in a few minutes to help with this. In the meantime you could read other people's solutions to the same problem with a search.

phranque

WebmasterWorld Administrator phranque us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 4640634 posted 2:57 am on Jan 28, 2014 (gmt 0)

RewriteRule ^order/specials$ http://www.example.com/mm5/merchant.mvc?Screen=SPECIALS [L]

was the request for http://www.example.com/order/specials or was another hostname requested?

MarkOly



 
Msg#: 4640634 posted 3:10 am on Jan 28, 2014 (gmt 0)

was the request for http://www.example.com/order/specials or was another hostname requested?

That's right. That's the exact request. They are both on the same host. And my rule for this is my second rule in the chain. Thanks.

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4640634 posted 3:48 am on Jan 28, 2014 (gmt 0)

I can't do that because I don't want to do an external redirect.

But you are doing an external redirect. The moment you include a protocol-plus-domain in the target, it becomes a redirect even if there's no [R] flag. To keep it as an internal rewrite, the target has to start in / alone, like your other posted rule.

Speaking of which...
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^.]+[^./]\ HTTP/
RewriteRule ^([^.]+[^./])$ /$1.htm [L]

Conditions looking at THE_REQUEST are only necessary when there's a possibility that the path given in the rule can be the result of internal activity, such as an explicit "index.php". Here it isn't needed. In fact it's rare for a THE_REQUEST condition to be used in a rule producing an internal rewrite; you see them more often in rules calling for external redirects.

MarkOly



 
Msg#: 4640634 posted 4:28 am on Jan 28, 2014 (gmt 0)

But you are doing an external redirect. The moment you include a protocol-plus-domain in the target, it becomes a redirect even if there's no [R] flag. To keep it as an internal rewrite, the target has to start in / alone, like your other posted rule.

Ohhh. Okay. For some reason, I thought leaving the [R] off is what told it to go internal rewrite. I think I see what I need to do here. I'll work on this over the next couple days. It's been awhile since I've worked with any of these rules. I have to reaclimate. Thanks Lucy!

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4640634 posted 9:52 pm on Jan 28, 2014 (gmt 0)

If the target includes protocol and hostname you have a redirect.
If there is no [R] flag OR there is an [R] flag with no status code then you have a 302 redirect.
If you specify a status code then that is what will be returned.

MarkOly



 
Msg#: 4640634 posted 2:18 am on Jan 29, 2014 (gmt 0)

If the target includes protocol and hostname you have a redirect.
If there is no [R] flag OR there is an [R] flag with no status code then you have a 302 redirect.
If you specify a status code then that is what will be returned.

Thanks g1smd. I think this should be pretty simple then:

# Internally rewrite specific Miva Merchant pages
RewriteRule ^order/specials$ /mm5/merchant.mvc?Screen=SPECIALS [L]

It works. Logs now return a 200. I think that's it. Thanks for the help!

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4640634 posted 6:14 pm on Jan 29, 2014 (gmt 0)

There are two other steps to complete the process.

One is to make sure that the links on the pages of the site point to the friendly URLs.

The other is to add a redirect so that anyone requesting a parameter-based URL found in an old bookmark or stale SERP is redirected to the new URL. This avoids a Duplicate Content issue.

MarkOly



 
Msg#: 4640634 posted 7:35 pm on Jan 29, 2014 (gmt 0)

There are two other steps to complete the process.

One is to make sure that the links on the pages of the site point to the friendly URLs.

The other is to add a redirect so that anyone requesting a parameter-based URL found in an old bookmark or stale SERP is redirected to the new URL. This avoids a Duplicate Content issue.

Thanks g1msd. Yeah, this his always been a static page with url: orders/specials. Any time I wanted to add or remove products to it, I would have to do it manually. So a couple months ago, I decided it would be easier to make it a dynamic page (which requires the funky Miva Merchant url). Any products I want to put on special, I assign a special item number range to. The Specials page is setup to pickup that range of item numbers. It saves me a little bit of work.

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4640634 posted 9:19 pm on Jan 29, 2014 (gmt 0)

There are two other steps to complete the process.

I was all ready to start whining "But I said that!" when I realized this is a different thread. In the boilerplate, Step 1 is the redirect, Step 2 is the rewrite and Step 0 is the internal linking ;)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved