Forum Moderators: phranque

Message Too Old, No Replies

Some help with httacess on localhost please

         

Lussay

1:46 pm on Jul 30, 2011 (gmt 0)

10+ Year Member



Hi,

I have a site that works perfectly on the live domain.

I tried setting it up on my localhost server though, in order to develop some things, however the redirects don't work properly I am thinking.

I've modified the hosts file under system32 to point to the site and I've tried a lot of stuff but I can not seem to figure it out. By the way, the site resides exactly in the htdocs in a xampp instalation folder, with no other subfolders.


# mod_rewrite set:

Options +Includes

RewriteEngine on

# redirect if NOT www.site.com (exactly) to www.site.com
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.site\.com
RewriteRule (.*) [site.com...] [R=301,L]

# Styles directory is not rewrited
RewriteCond %{REQUEST_URI} ^(/+)styles/(.+)$
RewriteRule (.*) $1 [L]

# banners directory is not rewrited
RewriteCond %{REQUEST_URI} ^(/+)banners/(.+)$
RewriteRule (.*) $1 [L]

# images directory is not rewrited
RewriteCond %{REQUEST_URI} ^(/+)images/(.+)$
RewriteRule (.*) $1 [L]

# generator directory is not rewrited
RewriteCond %{REQUEST_URI} ^(/+)generator/(.+)$
RewriteRule (.*) $1 [L]

# favicon.gif
RewriteCond %{REQUEST_URI} ^(/+)favicon.gif$
RewriteRule (.*) $1 [L]

# robots.txt
RewriteCond %{REQUEST_URI} ^(/+)robots.txt$
RewriteRule (.*) $1 [L]

# googled9ea952696e75819.html
RewriteCond %{REQUEST_URI} ^(/+)googled9ea952696e75819.html$
RewriteRule (.*) $1 [L]

# index.html
RewriteCond %{REQUEST_URI} ^(/+)index.html$
RewriteRule (.*) $1 [L]

# sitemap.xml
RewriteCond %{REQUEST_URI} ^(/+)sitemap.xml$
RewriteRule (.*) $1 [L]

# ror.xml
RewriteCond %{REQUEST_URI} ^(/+)ror.xml$
RewriteRule (.*) $1 [L]

# sitemap.html
RewriteCond %{REQUEST_URI} ^(/+)sitemap.html$
RewriteRule (.*) $1 [L]

# Administration
RewriteCond %{REQUEST_URI} ^(/+)admin/(.*)$
RewriteRule (.*) %{DOCUMENT_ROOT}/admin/index.php [L,QSA]

# SystemCommands (starting with prefix _)
RewriteCond %{REQUEST_URI} !^(/+)syscmd.php$
RewriteCond %{REQUEST_URI} ^(/+)_([^/]+)$
RewriteRule ^_(.*)$ %{DOCUMENT_ROOT}/syscmd.php?cmd=$1 [L,QSA]

# SystemCommands (ending with _(.*))
RewriteCond %{REQUEST_URI} !^(/+)syscmd.php$
RewriteCond %{REQUEST_URI} (/+)_([^/]+)$
RewriteRule ^(.*)/_([^/]+)$ %{DOCUMENT_ROOT}/syscmd.php?page=$1&cmd=$2 [L,QSA]

# Rewrite orther
RewriteCond %{REQUEST_URI} !^(/+)index.php(.*)$
RewriteCond %{REQUEST_URI} !^(/+)syscmd.php$
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/index.php?page=$1 [L,QSA]

# If Rewriting Failure, Show error message (Internal backup)
RewriteCond %{REQUEST_URI} !^(/+)index.php$
RewriteCond %{REQUEST_URI} !^(/+)syscmd.php$
RewriteRule (.*) \1 [F]


Thanks for your help in advance.

Regards,

Lucian

g1smd

1:55 pm on Jul 30, 2011 (gmt 0)

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



For a simple function that code is way over-complicated.

One thing to first fix is to delete (.*)$ from every condition where you don't actually re-use the captured %n backreference. You're wasting processor cycles reading to the end of the input, capturing it for re-use then not re-using it.

The (/+) pattern matches one or more contiguous slashes. I assume that's the wrong pattern and the capturing parentheses are also not required here.

Literal periods in patterns should be escaped.

Rather than having a huge number of rules, you should make use of the "local OR" function (this|that|other) to reduce the number of lines of code.

Leading "begins with" ^(.*) patterns are always incorrect. The (.*) captures "everything". Since the rule pattern expects to find other stuff after "everything", it has to back off and retry thousands of times to find a match.

The \1 target will likely throw an error. Use a hyphen for "no action". RewriteRule (.*) - [F]