Forum Moderators: phranque

Message Too Old, No Replies

Rewrite on localhost problem

         

Karma

9:23 am on Apr 18, 2008 (gmt 0)

10+ Year Member



Hi all,

I'm trying to set my site up on my local machine using the following rules (which is taken from my live site, which works fine on the domain).

-----------------------------------------------------------------
RewriteEngine on
#
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com(:[0-9]+)?$
RewriteRule (.*) [localhost...] [R=301,L]
#
RewriteRule ^([^_]+)_([^/]+)/([^_]+)_([^/]+)/([^_]+)_([^/]+)/([^_]+)_([^/]+)/([^_]+)_([^/]+)/?$ /index.php?$1=$2&$3=$4&$5=$6&$7=$8&$9=$10 [L]
#
RewriteRule ^([^_]+)_([^/]+)/([^_]+)_([^/]+)/([^_]+)_([^/]+)/([^_]+)_([^/]+)/?$ /index.php?$1=$2&$3=$4&$5=$6&$7=$8 [L]
#
RewriteRule ^([^_]+)_([^/]+)/([^_]+)_([^/]+)/([^_]+)_([^/]+)/?$ /index.php?$1=$2&$3=$4&$5=$6 [L]
#
RewriteRule ^([^_]+)_([^/]+)/([^_]+)_([^/]+)/?$ /index.php?$1=$2&$3=$4 [L]
#
RewriteCond $1 !^noexist$
RewriteRule ^([^_]+)_([^/]+)/?$ /index.php?$1=$2 [L]
-----------------------------------------------------------------

When I use the above, I get the error "The page isn't redirecting properly". I'm not sure what I should be putting in the "RewriteCond %{HTTP_HOST} !^www\.mydomain\.com(:[0-9]+)?$" line for localhost.

Any ideas? I'm at a loss

jdMorgan

2:12 pm on Apr 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You probably want to disable the domain redirect rule when testing on localhost:

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^localhost\.?(:[0-9]+)?$
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

You could use the original code from your real server if you added an entry to your test server's 'hosts' file to define 127.0.0.1 as the local DNS for your real domain name. When done testing, simply delete that entry from 'hosts'. On Windows XP, your hosts file is usually located at C:\windows\system32\drivers\etc\hosts

As for your rewrite/redirect to /test/myfolder, that should be handled in your local server configuration. That is, define DocumentRoot for your test domain to point to /test/myfolder, avoiding any need for a rewrite or redirect to /test/myfolder, and eliminating all the related complications.

Jim

[edited by: jdMorgan at 2:13 pm (utc) on April 18, 2008]

Karma

9:42 am on Apr 21, 2008 (gmt 0)

10+ Year Member



Hey jd, thanks 'again'! I'm now running the domain on my localserver and things are working great :)

g1smd

6:19 pm on Apr 22, 2008 (gmt 0)

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



I edit the HOSTS file on the PC so that localhost is also known as test.domain.com.

I can then use the same rules with an optional (test.)? in it.