Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule only working on Localhost?

htaccess rewriterule only works on localhost and not live website?

         

Skyhigh

11:19 am on Jun 24, 2011 (gmt 0)

10+ Year Member



I've got a rule which should return a 410 (page gone) for any URL that starts with:
/index.php?route=product/browse

Here's the htaccess rule:
RewriteCond %{QUERY_STRING} ^route=product/browse [NC]
RewriteRule ^index\.php$ /? [NC,R=410,L]



This works fine when I run it on my localhost, but when I move my updated .htaccess to the live website (www.blahblah.com) - the rule doesn't appear to work.

Even when I remove all other rules (to make sure it's not a conflict) - it will doesn't work on the live site.


Any suggestions greatly appreciated!

lucy24

5:28 pm on Jun 24, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I swear it's only hours since I last cited Rule #2 (Rule #1 doesn't apply here): Instead of saying "it doesn't work", say exactly what happens. Or say that nothing happens, if that's the case. What happens when you navigate to an affected page? That is: what do you see onscreen, and what does your browser's address bar say?

If the page is going to be gone anyway, you don't need to rewrite it to anything. You're just confusing your server ;)
There is a special substitution string named '-' which means: NO substitution! This is useful in providing rewriting rules which only match URLs but do not substitute anything for them.

(Bookmark this page [httpd.apache.org] if you haven't already!)

The php element adds a layer of complication. All kinds of things can happen to the page between the time you click on a link (or type in the address) and the page arrives at htaccess, or between the time it leaves htaccess and arrives on your screen.

What happens if you leave off the ending anchor $ from the rule? Could any page other than index.php conceivably have the "route=product/browse" query string? (Those are two separate questions.) You may be making your pattern more exact than it needs to be.

g1smd

11:36 pm on Jun 24, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The
R=410
syntax works only on recent 2.x Apache versions (don't ask me the exact version number).

This will serve the 410 ErrorDocument file and the 410 status in the header:
RewriteCond %{QUERY_STRING} ^route=product/browse [NC] 
RewriteRule ^index\.php$ - [G]

when
example.com/index.php?route=product/browse
is requested.

It will not do so when
example.com/?route=product/browse
or
example.com/index.php?somestuff=whatever&route=product/browse
is requested.