Forum Moderators: phranque
Very new to working with server technologies, but know my way around XHTML and CSS and know enough to cause troubles with PHP, but I'm having a wicked time getting background images to display on a 302 redirect to a temporary page. Here's the code I'm running:
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^11\.111\.111\.111
RewriteCond %{REQUEST_URI} !^/default\.html$
RewriteRule ^(.*)$ http://example.com/default.html [R=302,L]
Styles are in the top of default.html and image paths are correct to my eye.
Bluehost support said the htaccess code I'm running is the problem and I shouldn't be using this method anyway?
Any thoughts or help super appreciated! Wicked glad to have found this place, perfect reading material or those late nights.
~Larkin
[edited by: jdMorgan at 4:30 pm (utc) on Nov. 27, 2009]
[edit reason] example.com [/edit]
Think in terms of 'redirecting client requests for specific URLs' to simplify matters, since that is how mod_rewrite makes its decisions...
What URLs do you wish to redirect?
What URLs do you not wish to redirect?
The 'intersection' of the answers to these two questions indicates the most efficient solution.
It could be as simple as saying "I want to redirect all URL requests, except for 'default.html' and any image, CSS, or external JavaScript file URLs" -- but take extreme care here... What about your custom error page URLs? robots.txt file? sitemap.xml? Google/Yahoo/Bing webmaster tools site-validation/verification file URLs?
Solid definition first, then code.
Jim
Basically, I want to redirect client requests for [poptoptcreative.com...] and any subpages to [poptopcreative.com...]
But I want to allow my IP through so that I can continue working on the site.
My ultimate goal is to make sure normal human visitors trying to view my site see a temporary splash page with my background images. Right now, they get sent to default.html, but no images appear, just text. Is there a rewrite rule or something I can add that allows images to be shown on this default.html page?
It's often not clear to those just getting into this that one little error, be it a syntax error caused by a typo, or a 'scope' or logic error in the definition of the 'goal' of the rule, can sink your site in the search engines, and if that matters to your bottom line, basically put you out of business.
So bear in mind that .htaccess is a server configuration file and toying with it is ill-advised. This is not a trivial enterprise. You've got to get it absolutely right -- no wiggle room.
Are all of your 'pages' of type .html? Or do you also have .php or .shtml or .htm or .shtm or .xml or .cfm or any other types of 'pages?'
Do you use custom error pages for 404, 410, 403 responses, etc.? If so, what are their URLs?
We're not being pedantic here, we are basically trying to avoid being involved in an "assisted suicide."
Jim
This is a WordPress site, so most pages are .php. I just spoke with my hosting service support people, and the gentleman I spoke with put a temporary redirect on the site through the control panel. He then changed htaccess to the following:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REMOTE_HOST} !^11\.11\.111\.111
RewriteRule ^/?$ "http\:\/\/example\.com\/default\.html" [R=302,L]
This appears to be working, meaning I have access to the site, others go to default.html and the page appears as I wanted it to appear.
Not sure if I'm doing any unintentional harm to my site with this, but hopefully not.
Again, thanks to you both for your input, and if this looks like I'm heading down the path of an assisted suicide, let me know!
Hopefully at somepoint by hanging around these forums I'll get a better grasp of this side of the web, as opposed to the pretty part!
~J
[edited by: jdMorgan at 4:28 pm (utc) on Nov. 27, 2009]
[edit reason] example.com [/edit]
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
This can be simplified greatly:
RewriteCond %{HTTP_HOST} ^[b]([/b]www[b]\.)?[/b]example[b]\[/b].com$ and the literal periods need to be escaped by adding the \ backslashes as above.
"http[b]\[/b]:[b]\[/b]/[b]\[/b]/example[b]\[/b].com[b]\[/b]/default[b]\[/b].html"
The quotes and all of the \ backslashes should be omitted.
http://example.com/default.html This part is a literal URL.
Just made those changes so now I have:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteCond %{REMOTE_HOST} !^11\.111\.111\.111
RewriteRule ^/?$ "http://example.com/default.html" [R=302,L]
Appears to be working fine. Thanks for the simplification.
Larkin
[edited by: jdMorgan at 5:00 pm (utc) on Nov. 27, 2009]
[edit reason] example.com [/edit]
This could indeed still be a case of assisted suicide, because you need to answer all the questions I asked -- at least for yourself and your hosting-company "helper." The 'exclusion list' needs to be thorough, or you could put your server into an 'infinite' redirection loop.
With what we (here) know so far, this would be my best current guess:
RewriteEngine on
# Temporarily (302) redirect all html and php page requests to the "maintenance" page, excluding
# requests for my own IP address, the maintenance page itself, and any custom error pages.
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteCond %{REMOTE_ADDR} !=11.11.111.111
RewriteCond $1 !^default\.html$
RewriteCond $1 !^custom-400-error-page\.html$
RewriteCond $1 !^custom-403-error-page\.html$
RewriteCond $1 !^custom-404-error-page\.html$
RewriteCond $1 !^custom-405-error-page\.html$
RewriteCond $1 !^custom-408-error-page\.html$
RewriteCond $1 !^custom-409-error-page\.html$
RewriteCond $1 !^custom-410-error-page\.html$
RewriteCond $1 !^custom-411-error-page\.html$
RewriteCond $1 !^custom-412-error-page\.html$
RewriteCond $1 !^custom-413-error-page\.html$
RewriteCond $1 !^custom-414-error-page\.html$
RewriteCond $1 !^custom-415-error-page\.html$
RewriteCond $1 !^custom-500-error-page\.html$
RewriteCond $1 !^custom-501-error-page\.html$
RewriteCond $1 !^custom-503-error-page\.html$
RewriteCond $1 !^custom-505-error-page\.html$
RewriteRule ^(([^/]*/)*([^.]+\.)+(s?html?¦php[0-9]+))?$ http://example.com/default.html [R=302,L]
Note also the several subtle and not-so-subtle changes to the first few RewriteConds -- they're important, as is everything else...
The regex pattern in the RewriteRule is intended to catch all .html and .php page requests, as well as requests for variants on those filetypes, such as .shtml or .htm, and .php4, .php5, etc. Note that the entire pattern match is also optional, which allows it to also match requests for your 'home page' at "example.com/"
Important:
Replace the broken pipe "¦" character in the RewriteRule pattern with a solid pipe character from your keyboard before use; posting on this forum modifies the pipe characters, and the code won't work unless they're replaced.
Be very sure that the hostname in the redirect target address matches the hostname that you are 'known by' in search engine listings -- if most of your inbound links are to 'www.example.com' and that "www" hostname is what shows up in search engine listings for your pages, then you must include that 'www.' in the redirect target address.
OK, so that's all the "speculation time" I have for today -- I hope it helps. :)
Jim