tags:

views:

35

answers:

2

I'm currently using an .htaccess to get round a problem with a CMS, nothing major and an htaccess fix is tidy enough.

I'm currently using the format...

redirect 301 /pictures.html http://www.domain.com/gallery.html

The problem though this causes is that the CMS uses pictures.html?vars=here to select galleries and so the redirect breaks this part of it. Is there any way I can redirect pictures.html but not when it has variables attached?

A: 

You can redirect everyone except your webserver by detecting the IP address like so:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_HOST} !^123\.45\.67\.89
RewriteRule \.html$ /alternate_page.html [R=301,L] 
Dan
+1  A: 

For example, add something like

RewriteCond %{QUERY_STRING} ^$

before your rule.

wRAR
Will that work if doesn't explicitly set up a ReWriteRule to do the redirect? I am pretty sure that redirect is a mini-version of rewrite, but can you throw in rewrite conditions without turning the rewrite engine on?
Anthony
I thought the author used `RewriteRule`.
wRAR
I'm open to what rules to use, I have mod_rewrite on.I'm not sure what I should be doing with this solution though.
Leonard
Change your rule to something like `RewriteRule /pictures.html$ http://www.domain.com/gallery.html [R=301,L]` and add aforementioned `RewriteCond` before it.
wRAR
It doesn't redirect pictures.html at all. :(
Leonard
If you write your rules in `.htaccess`, not in `httpd.conf`, you need to use relative paths, so if `.htaccess` is in the same directory as `pictures.html`, use `pictures.html` instead of `/pictures.html`.
wRAR
Didn't get it working with the ^$ but swapped that for !view as the url should always contain view=something and it works a charm. Thanks for the help guys.
Leonard