Forum Moderators: phranque

Message Too Old, No Replies

Is this htaccess right?

         

efendi

1:21 pm on Nov 24, 2008 (gmt 0)

10+ Year Member



hi everybody,
i would ask, whether this htaccess is right or not.
it should redirect index.html and .php to the root and do some other things.
----------------------------------------------------

RewriteEngine On
RewriteCond %{SERVER_PORT} =443
RewriteRule ^robots\.txt robots_ssl.txt [L]
# example ip, in the live htaccess, there placed the ip from the domain
RewriteCond %{HTTP_HOST} !^192.168.0.10(:80)?
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(html?¦php)\ HTTP/
RewriteCond %{SERVER_PORT} !=443
RewriteCond %{REQUEST_METHOD} !^POST
RewriteRule ^index\.(html?¦php) http://www.example.com/ [R=301,L]

----------------------------------------------------

(update)
sorry, i would specify my question: can this htaccess affect in bad way the ranking in searchenginges

thank you

[edited by: engine at 11:51 am (utc) on Nov. 25, 2008]
[edit reason] please always use example.com [/edit]

g1smd

8:59 pm on Nov 24, 2008 (gmt 0)

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



*** and do some other things ***

That is far too vague to be helpful in any way.

.

One thing is that your redirects are not in the correct order. The general non-www to www redirect should always be the last of the redirects.

Split the code up with a blank line between each rule block, and add a comment line to the start of each block explaining what that rule does.

You have the rewrite listed first. All of the rewrites must appear after all of the redirects.

efendi

10:00 am on Nov 25, 2008 (gmt 0)

10+ Year Member



okay, i will try it (but my english is very bad, i think in german i can better explain it):

¦ RewriteCond %{SERVER_PORT} =443
¦ RewriteRule ^robots\.txt robots_ssl.txt [L]
+--------------------------------------------
this rule gives the searchengines an another robots.txt if 443 is the requested port.

¦RewriteCond %{HTTP_HOST} !^192.168.0.10(:80)?
¦RewriteCond %{HTTP_HOST} !^www\.example\.com
¦RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
+-----------------------------------------------------
i think, here should redirect the request to the full address. if ip-request or non-www should go www. correct?
but is the ip-redirect required? and whats up with the portnumber und the question mark at the end of the line?

¦RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(html?¦php)\ HTTP/
+-----------------------------------
index.html or index.php should redirect to root. okay?

¦RewriteCond %{SERVER_PORT} !=443
¦RewriteCond %{REQUEST_METHOD} !^POST
¦RewriteRule ^index\.(html?¦php) http://www.example.com/ [R=301,L]
+-----------------------------------------------------
i don't know what happens here. it's a mytery for me.
seems to be duplicate with the rule above?

my webmaster is in vacation for three weeks and he created this htaccess. my guess is, that something doesn't works properly.
if someone can help me, i would be grateful for the informations.

thanks

[edited by: engine at 11:51 am (utc) on Nov. 25, 2008]
[edit reason] please always use example.com [/edit]

phranque

10:59 am on Nov 25, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you mean "if non-ip-request..."?
the 192.168.0. ip is an internal network address, so you are preventing an external redirect in that case.

the (:80)? is an optional port specification in the url.
80 is the typical http port and the () groups it and the ? makes it 0 or 1 occurrence of the group.

the last two RewriteCond directive prevent the redirect to root if a form is submitted (the http request method for a submitted form is usually a POST, as opposed to a GET) or if it is a secure request (443 is the typical https port) and then the RewriteRule does the work.
the first RewriteCond only sets the condition for executing the following 2 RewriteCond directives and then the RewriteRule.

efendi

11:16 am on Nov 25, 2008 (gmt 0)

10+ Year Member



hi phranque,
the 192.168-ip is only an example. the live htaccess contains the real ip from the domain.
thanks for your statement. is this htaccess now okay or can it be harmful for the behavior of the searchengines?

greatings

jdMorgan

6:38 pm on Nov 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Correcting rule order, handling un-handled SSL cases, and making a few tweaks, I'd suggest:

RewriteEngine on
#
# Redirect non-POST requests for index.php, index.html, or index.htm to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(html?¦php)\ HTTP/
RewriteCond %{REQUEST_METHOD} !^POST
RewriteCond %{SERVER_PORT}s ^(443(s)¦[0-9]+s)$
RewriteRule ^index\.(html?¦php[b])$[/b] ht[b]tp%2:[/b]//www.example.com/ [R=301,L]
#
# If requested hostname is not IP address, exact canonical domain, or
# blank (for HTTP/1.0), redirect requests to canonical domain
RewriteCond %{HTTP_HOST} !^192.168.0.10[b]$[/b]
RewriteCond %{HTTP_HOST} !^(www\.example\.c[b]om)?$[/b]
RewriteCond %{SERVER_PORT}s ^(443(s)¦[0-9]+s)$
RewriteRule (.*) ht[b]tp%2:[/b]//www.example.com/$1 [R=301,L]
#
# Serve alternate robots.txt for SSL requests
RewriteCond %{SERVER_PORT} =443
RewriteRule ^robots\.txt robots_ssl.txt [L]

Note that the redirects now preserve the initial SSL/non-SSL state by passing an 's' into the protocol string if the request was made on SSL port 443.

Important: Change the broken pipe "¦" characters to solid pipe characters before use; Posting on this forum modifies the pipe characters.

Jim

efendi

10:26 am on Dec 1, 2008 (gmt 0)

10+ Year Member



thank you, jdMorgan.

i see some charakters in bold, like this:
tp%2 oder om)?$
are this mistakes from the forum or is this the tweaks you made?

greatings

efendi

10:50 am on Dec 1, 2008 (gmt 0)

10+ Year Member



i have a last question: can my first posted htaccess damage or penalize my ranking in the searchengines?

thank you all for the help!

g1smd

10:54 am on Dec 1, 2008 (gmt 0)

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



Yes, your first one can cause problems, exposing internal server paths, causing redirection chains, and so on.

The bold stuff is highlighted because those are the things to pay the most attention to.

efendi

11:00 am on Dec 1, 2008 (gmt 0)

10+ Year Member



thanks, g1smd,
i will copy and paste the corrected htaccess from jdMorgan to my domain and then i cross my fingers and wait. this forum rocks!
(and if this htaccess helps, i will pray for you guys!)

greatings
efendi