Forum Moderators: phranque

Message Too Old, No Replies

.htaccess

I need help with .htaccess file

         

ahunter61

6:34 pm on Feb 12, 2011 (gmt 0)

10+ Year Member



I know very little about these files, and would like to know if there are any problems that need fixing. I know there should be some redirects from old pages and I do use server side includes. I see some things that refer to guides4fish.com, which is an old domain name no longer used. should they be removed?
Thanks Pete



RewriteEngine on

#
# Uncomment the statement below if you want to make use of
# HTTP authentication and it does not already work.
# This could be required if you are for example using PHP via Apache CGI.
#
#<IfModule mod_rewrite.c>
#RewriteEngine on
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#</IfModule>

<Files "config.php">
Order Allow,Deny
Deny from All
</Files>

<Files "common.php">
Order Allow,Deny
Deny from All
</Files>

AddHandler server-parsed .htm .html

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^amarker\.html$ "http\:\/\/www\.conneroutdoors\.com" [R=301,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^phpsqlsearch_genxml1\.php$ "http\:\/\/www\.conneroutdoors\.com" [R=301,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^arizona\.html$ "http\:\/\/www\.conneroutdoors\.com\/hunting\/arizona\.html" [R=301,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^alabama\.html$ "http\:\/\/www\.conneroutdoors\.com\/hunting\/alabama\.html" [R=301,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^southdakota2_hunting\.html$ "http\:\/\/www\.conneroutdoors\.com\/hunting\/southdakota\.html\.html" [R=301,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^phpBB3\/viewtopic\.php$ "http\:\/\/www\.conneroutdoors\.com\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^conneroutdoors.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.conneroutdoors.com$
RewriteRule ^fishing\/fishindex\.htm$ "http\:\/\/www\.conneroutdoors\.com\/fishindex\.html" [R=301,L]

RewriteCond %{HTTP_HOST} ^conneroutdoors.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.conneroutdoors.com$
RewriteRule ^blogs\.html$ "http\:\/\/www\.conneroutdoors\.com\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^conneroutdoors.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.conneroutdoors.com$
RewriteRule ^forum\.html$ "http\:\/\/www\.conneroutdoors\.com" [R=301,L]

RewriteCond %{HTTP_REFERER} !^http://conneroutdoors.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://conneroutdoors.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://guides4fish.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://guides4fish.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://guides4fish.conneroutdoors.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://guides4fish.conneroutdoors.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://mail.conneroutdoors.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://mail.conneroutdoors.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://mail.guides4fish.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://mail.guides4fish.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://mail.pleasantriverguides.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://mail.pleasantriverguides.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://pleasantriverguides.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://pleasantriverguides.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://pleasantriverguides.conneroutdoors.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://pleasantriverguides.conneroutdoors.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.conneroutdoors.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.conneroutdoors.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.guides4fish.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.guides4fish.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.guides4fish.conneroutdoors.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.guides4fish.conneroutdoors.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mail.conneroutdoors.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mail.conneroutdoors.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mail.guides4fish.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mail.guides4fish.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mail.pleasantriverguides.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mail.pleasantriverguides.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.pleasantriverguides.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.pleasantriverguides.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.pleasantriverguides.conneroutdoors.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.pleasantriverguides.conneroutdoors.com$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]

RewriteCond %{HTTP_HOST} ^conneroutdoors.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.conneroutdoors.com$
RewriteRule ^phpBB3\/index\.php$ "http\:\/\/www\.conneroutdoors\.com" [R=301,L]

RewriteCond %{HTTP_HOST} ^conneroutdoors.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.conneroutdoors.com$
RewriteRule ^contact\.html\/$ "http\:\/\/www\.conneroutdoors\.com\/contact\.html" [R=301,L]


and this is a 2nd htaccess file for a old domain name guides4fish.com

# <deactivate guides4fish.com>
# Reason for deactivation: No Payment Received
# please contact us to remedy this situation as soon as possible
RewriteEngine On
RewriteCond %{HTTP_HOST} ^guides4fish.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.guides4fish.com$
RewriteRule ^(.*) [box399.bluehost.com...] [L,R=302]
# </deactivate>

jdMorgan

9:22 pm on Feb 17, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Lots and lots of apparent duplication and redundancy, plus a few errors.

Do make a back-up before testing this, though....

For your main .htaccess file, I'd suggest:

# Forbid image hotlinking if referrer is non-blank and does not start with our own hostname
RewriteCond %{HTTP_REFERER} !^(http://conneroutdoors.com(/.*)?)?$
RewriteRule \.(jpe?g|gif|png|bmp)$ - [NC,F]
#
# Externally redirect old, obsolete, or incorrect URLs to new and correct URLs
RewriteRule ^(amarker|blogs|forum)\.html$ http://www.conneroutdoors.com/ [R=301,L]
RewriteRule ^(phpsqlsearch_genxml1|phpBB3/(index|viewtopic))\.php$ http://www.conneroutdoors.com/ [R=301,L]
RewriteRule ^(arizona|alabama)\.html$ http://www\.conneroutdoors.com/hunting/$1.html [R=301,L]
RewriteRule ^southdakota2_hunting\.html$ http://www.conneroutdoors.com/hunting/southdakota.html [R=301,L]
RewriteRule ^fishing/fishindex\.htm$ http://www.conneroutdoors.com/fishindex.html [R=301,L]
RewriteRule ^contact\.html/$ http://www.conneroutdoors.com/contact\.html [R=301,L]
#
# Externally redirect all non-blank non-canonical hostname requests to the canonical hostname
RewriteCond %{HTTP_HOST} !^(www\.connersoutdoors\.com)?$
RewriteRule ^(.*)$ http://www.connersoutdoors.com/$1 [R=301,L]

This is much more compact, and assuming that you're only running one hostname (www.connersoutdoors.com) in this virtual server, should entirely replace all of the main-htaccess-file code that you had. It also adds a hostname canonicalization redirect which makes many of the other code reductions possible.

See the documentation cited in our Apache Forum Charter, especially the mod_rewrite documentation which will help you to identify which directive fields are regular-expressions patterns and which are not: Character-escaping is only required only within regular-expressions patterns and only on some characters in some contexts. Your original code was rife with unnecessary quoting and escaping, wasting CPU time as well as making the code very hard to read and to check for correctness.

Jim