Welcome to WebmasterWorld Guest from 54.211.11.57

Forum Moderators: Ocean10000 & incrediBILL & phranque

Redirection to Under construction page

     
10:13 am on Mar 8, 2017 (gmt 0)

Senior Member

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

joined:Oct 25, 2006
posts: 1035
votes: 0


# Under construction
RewriteRule ^http://www.example.com$ http://www.example.com/en-GB/website-under construction.html [R,L]

Is this the correct line or how to use {HTTP_HOST} in this example?
Need help.
10:48 am on Mar 8, 2017 (gmt 0)

Administrator from US 

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

joined:Dec 27, 2006
posts:3114
votes: 122


It is a really bad idea to redirect people (or bots) to an "under construction" page. Since well over 15 years, you just don't see this kind of page being offered. It would be better to have a blank index page until you have something in place. Even better is to not have created the new directory until it is ready for everyone. Just my opinion.

About the rule though - the way your rule is written, it is using mod_alias. IF it is the only rule in your htaccess file you can probably use a rule like that, but if you have any mod_redirect rules in the same htaccess file you may have unexpected results.

To get the best help, it helps to clearly explain the environment, to spell out just what you are trying to do and where the file you want to edit is located - is this htaccess rule in the /en-GB/ folder or in the root directory?
11:50 am on Mar 8, 2017 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:10761
votes: 45


RewriteRule ^http://www.example.com$ http://www.example.com/en-GB/website-under construction.html [R,L]

the pattern in the RewriteRule is matched against the current path, so it won't try to match the protocol or hostname.
do you want to redirect the home page only or all requested paths to the "under construction" page?
11:57 am on Mar 8, 2017 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:10761
votes: 45


It is a really bad idea to redirect people (or bots) to an "under construction" page.

not so bad with a temporary redirect.
the R flag of the RewriteRule directive defaults to a 302, but i would suggest explicitly specifying the 302 response status code with this form:
[R=302,L]

About the rule though - the way your rule is written, it is using mod_alias. IF it is the only rule in your htaccess file you can probably use a rule like that, but if you have any mod_redirect rules in the same htaccess file you may have unexpected results.

RewriteRule is a mod_rewrite directive.
Rewrite and RewriteMatch are mod_alias directives.
4:30 pm on Mar 8, 2017 (gmt 0)

Administrator from US 

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

joined:Dec 27, 2006
posts:3114
votes: 122


RewriteRule is a mod_rewrite directive.
Rewrite and RewriteMatch are mod_alias directives.

You're right of course. :)


Note to self: try not to post before either sleep or coffee.
9:24 pm on Mar 8, 2017 (gmt 0)

Senior Member

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

joined:Oct 25, 2006
posts: 1035
votes: 0


Do you want to redirect the home page only or all requested paths to the "under construction" page?
Yes, all pages within 3 seconds and button.

Redirection is not a bad thing. CloudFlare or other CDN use all the time Development Mode. It means it is a temporary redirect.

What is the correct line in this case as domain or host is the same all the time.
12:49 am on Mar 9, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:13543
votes: 404


I wouldn't do it that way at all. Instead, return a manual 503 (or other, see below) response with an appropriate error document.

ErrorDocument 503 /underconstruction.html

RewriteCond %{REQUEST_URI) !/underconstruction
RewriteRule (^|/|\.html)$ - [R=503,L]

Don't be fooled by the "R"; it's a catchall for anything that doesn't have a flag of its own (i.e. [F] or [G]). It doesn't have to be 503; you can even make up a number, so long as it isn't something your server normally uses. But 503 does carry a built-in "try again in a while".
2:43 am on Mar 9, 2017 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:10761
votes: 45


Do you want to redirect the home page only or all requested paths to the "under construction" page?

Yes, all pages


in that case, i would definitely use the 503 as suggested by lucy24.

https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.4
10.5.4 503 Service Unavailable

The server is currently unable to handle the request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay. If known, the length of the delay MAY be indicated in a Retry-After header. If no Retry-After is given, the client SHOULD handle the response as it would for a 500 response.


note that this is one of the very few case where the Retry-After HTTP Response header is indicated.

https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.37
14.37 Retry-After

The Retry-After response-header field can be used with a 503 (Service Unavailable) response to indicate how long the service is expected to be unavailable to the requesting client. This field MAY also be used with any 3xx (Redirection) response to indicate the minimum time the user-agent is asked wait before issuing the redirected request. The value of this field can be either an HTTP-date or an integer number of seconds (in decimal) after the time of the response.
10:22 pm on Mar 14, 2017 (gmt 0)

Senior Member

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

joined:Oct 25, 2006
posts: 1035
votes: 0


So, in my case it is the best way to use:
ErrorDocument 503 /underconstruction.html

RewriteCond %{REQUEST_URI) !/underconstruction
RewriteRule (^|/|\.html)$ - [R=503,L]
12:01 am on Mar 15, 2017 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:10761
votes: 45


ErrorDocument 503 /underconstruction.html

RewriteCond %{REQUEST_URI) !/underconstruction
RewriteRule (^|/|\.html)$ - [R=503,L]


if a user agent requested /news/underconstruction-in-the-city.html, for example, it would not get a 503 response.
i would be as specific as possible with the conditional exclusion:
RewriteCond %{REQUEST_URI) !^/underconstruction\.html$
12:15 am on Mar 15, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:13543
votes: 404


Well, it's definitely what I'd do ;)

Incidentally, further research tells me the [L] flag isn't necessary when using a number outside the 3xx range. It won't do any harm; you just don't need it after all.

In this specific case, the (^|/|\.html)$ element is so that if ordinary robots (search engines and so on) crawl your site while you're in the middle of doing stuff, you might as well let them pick up images and stylesheets and other non-page content that they happen to ask for. Presumably those aren't changing.
9:50 pm on Mar 16, 2017 (gmt 0)

Senior Member

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

joined:Oct 25, 2006
posts: 1035
votes: 0


Thank you for all replies.
So, it is working example:

ErrorDocument 503 /underconstruction.html

#if a user agent requested /news/underconstruction-in-the-city.html
RewriteCond %{REQUEST_URI) !^/underconstruction\.html$
#non-page content also
RewriteRule (^|/|\.html)$ - [R=503]
1:32 am on Mar 17, 2017 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:10761
votes: 45


i would change the comments to more accurately reflect the intention:

#specify an error document for 503 Unavailable status code response
ErrorDocument 503 /underconstruction.html

#ruleset exclusion for error document(s)
RewriteCond %{REQUEST_URI) !^/underconstruction\.html$
#send 503 status code response for any requests for the root directory (null path), a subdirectory (path ends in /), or a .html file type (path ends in .html)
RewriteRule (^|/|\.html)$ - [R=503]
8:57 am on Mar 17, 2017 (gmt 0)

Senior Member

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

joined:Oct 25, 2006
posts: 1035
votes: 0


I have tested in real and created directory called test/index.html.

There is an error:
The page isnít redirecting properly

#specify an error document for 503 Unavailable status code response
ErrorDocument 503 /test/index.html

#ruleset exclusion for error document(s)
RewriteCond %{REQUEST_URI) !^/test/index\.html$

#send 503 status code response for any requests for the root directory (null path), a subdirectory (path ends in /), or a .html file type (path ends in .html)
RewriteRule (^|/|\.html)$ - [R=503]

How to add in the correct way SUBfolder test: RewriteRule (^|/|\.html)$ - [R=503] in this example?
11:04 am on Mar 17, 2017 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:10761
votes: 45


what path are you requesting and what response do you get?
8:35 pm on Mar 17, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:13543
votes: 404


Browser error or internal error?

If it's a browser error, your server logs will show 30 (or 20 or 50) identical or near-identical requests, each with a 300-class response.

For server errors, look at your error logs. They should live in the same place as regular access logs. Unlike RewriteLogs, it doesn't have to be your own server. Again, you will see either a series of requests for the same thing, or a cascade like
/filename.html
/dir/filename.html
/dir/dir/filename.html
/dir/dir/dir/filename.html
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members