Welcome to WebmasterWorld Guest from 54.167.177.207

Forum Moderators: Ocean10000 & incrediBILL & phranque

What does this .htaccess mean?

   
1:04 am on Oct 26, 2009 (gmt 0)

10+ Year Member



I am working on a clients site & normally when I want to redirect example-A.com to forward to example-B.com I would use the following code:

RewriteEngine on
RewriteRule ^(.*)$ [example-B.com...] [R=301,L]

& then whenever someone types in example-A.com they land on example-B.com.

Beyond blocking bad ip's and the above trick, I really don't know much about .htaccess.

This is the code I found:


RewriteEngine on
# -FrontPage-

IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName www.originalsite.net
AuthUserFile /home/originalsite/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/originalsite/public_html/_vti_pvt/service.grp

# disable directory browsing
Options All -Indexes

AddType application/x-httpd-php .html .htm .inc
AddHandler application/x-httpd-php .html .htm .incRewriteCond %{HTTP_HOST} ^originalsite.net$ [OR]
RewriteCond %{HTTP_HOST} ^www.originalsite.net$
RewriteRule ^/?$ "http\:\/\/www\.newsitename\.com" [R=301,L]

I did a bit of research & just want to know where I should put my redirect into this configuration.

+ what is going on at the bottom code? It looks like the original webdesigner tried to do a redirect -> which doesn't work. There are currently 2 sites with duplicate content, not a good thing.

7:50 am on Oct 26, 2009 (gmt 0)

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



These lines need to be escaped:

RewriteCond %{HTTP_HOST} ^originalsite[b]\.[/b]net$ [OR]
RewriteCond %{HTTP_HOST} ^www[b]\.[/b]originalsite[b]\.[/b]net$

but I would just do:

RewriteCond %{HTTP_HOST} [b]![/b]^www[b]\.[/b]newsitename[b]\.[/b]net$

There is way too much wrong with this line:

RewriteRule ^/?$ "http\:\/\/www\.newsitename\.com" [R=301,L]

should only be

RewriteRule [i]<pattern>[/i] http[b]://[/b]www[b].[/b]newsitename[b].[/b]com [R=301,L]

The

^/?$
pattern is also odd. It only forwards for root '/' requests, not for any requested folders or sub-pages. Additionally, you need
^$
if the code is in
.htaccess
and
^/$
if the code is in
httpd.conf
.

I would use

(.*)
for <pattern>, and that's one of the rare occasions when using
(.*)
is the right thing to do (often it is the most inefficient pattern to use).
6:23 pm on Oct 27, 2009 (gmt 0)

10+ Year Member



Thank you so much for your suggestions. Just a few more nubie questions. Sorry if they are really dumb, I just like to be careful.

1. Is the following correct? I only changed the bottom following your suggestions & the apache.org mod_rewrite pg.

2. I'm still confused on the indexignore. I get that it's saying to look at htaccess first, but what is the rest? & am I correct in seeing the header & readme is commented (if you saw the cpanel dir files you'd be horrified at how sloppy they are, still cleaning house)

Thank you again!

RewriteEngine on
# -FrontPage-

IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName www.originalsite.net
AuthUserFile /home/originalsite/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/originalsite/public_html/_vti_pvt/service.grp

# disable directory browsing
Options All -Indexes

AddType application/x-httpd-php .html .htm .inc
AddHandler application/x-httpd-php .html .htm .inc

# redirect old site to new site
RewriteRule (.*) [newsitename.com...] [R=301,L]

# always use www version
rewritecond %{http_host} ^newsitename.com [nc]
rewriterule ^(.*)$ [newsitename.com...] [r=301,L]

7:35 pm on Oct 27, 2009 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



The two redirects are potentially problematic in various ways, depending on whether old-site and new-site are hosted in the same filespace on this same server. In either case, though, it appears that you only need one rule:

# Externally redirect old site to new site (on a different
# server or in a separate filespace on this server)
RewriteRule ^(.*)$ http://www.newsitename.com/$1 [R=301,L]

- or -

# Externally redirect old site to new site (in this same server filespace)
RewriteCond %{HTTP_HOST} !^(www\.newsitename\.com)?$
RewriteRule ^(.*)$ http://www.newsitename.com/$1 [R=301,L]

Note that no allowance is made for incorrect-case requests or for requests using a FQDN or a hostname with a port number appended; This is intentional, since these too should be redirected.

You could also shorten the entire mod_access section to:


Order Deny,Allow
#
<LimitExcept GET POST>
Deny from all
</LimitExcept>

This disallows the use of any HTTP methods other than GET, HEAD, or POST. (HEAD is implied by GET.)

It is neither necessary (nor in most cases desirable) to use "Allow from all" since that will preclude using subsequent Denys to control access by IP address, user-agent, requested URI, etc. See Apache mod_access for details.

Jim

5:02 pm on Oct 28, 2009 (gmt 0)

10+ Year Member



Thank you for your patience & expertise! You've definitely cleared up a few points I was having trouble with even after reading & re-reading the documentation. :)

L

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month