Mod rewrite localhost problem

Discuss practical ways rearrange URLs using mod_rewrite.

Mod rewrite localhost problem

Postby bobmaine » Thu Jun 11, 2009 2:28 pm

Hello, new to the forum and want to ask about rewrite problem in localhost and I have ZERO knowledge about htaccess so any help from expert here will be appreciated..

Offline Server Info.
Windows xp sp3,
XAMPP for windows version 1.6.8
All config about mod rewrite has been setup properly.
Path installation: C:/xampp/htdocs/store/
URL root: http://localhost/store/
Added hosts configuration in C:\WINDOWS\system32\drivers\etc
127.0.0.1 www.mydomain.com
127.0.0.1 mydomain.com

Below is current htaccess on LIVE server that working perfectly (linux server), when I use following code in localhost and clicking on any links I get redirected to http://localhost/ instead of http://localhost/store/ , I don't have a problem viewing main url.

Then I modified my htaccess (help searching from google) like in AFTER EDIT but still have same problem.

CURRENT htaccess
Code: Select all
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain\.com$
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$
RewriteCond %{HTTP_HOST} ^.+\.mydomain\.com$
RewriteCond %{REQUEST_URI} !(images|membersdownload)$
RewriteCond %{REQUEST_FILENAME} !^/home/xxx/public_html/
RewriteRule ^(.*)$ %{HTTP_HOST}$1 [C]
RewriteRule ^(.*)\.mydomain\.com/.* /index.php?a=item&detail=$1 [QSA,L]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain\.com$ [NC]
RewriteRule ^purchase /index.php?a=item&detail=%1&buy
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain\.com$ [NC]
RewriteRule ^images /index.php?a=item&detail=%1&img
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain\.com$ [NC]
RewriteRule ^seller /index.php?a=item&detail=%1&pub
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain\.com$ [NC]
RewriteRule ^membersdownload /index.php?a=item&detail=%1&dwn
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain\.com$ [NC]
RewriteRule ^usersreviews /index.php?a=item&detail=%1&rev
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain\.com$ [NC]
RewriteRule ^fraudreport /index.php?a=item&detail=%1&awr
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain\.com$ [NC]
RewriteRule ^usersreview-(.*) /index.php?a=item&detail=%1&usersreview=$1}


AFTER EDIT
Code: Select all
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^localhost\.?(:[0-9]+)?$
RewriteCond %{HTTP_HOST} ^mydomain\.com$
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$
RewriteCond %{HTTP_HOST} ^.+\.mydomain\.com$
RewriteCond %{REQUEST_URI} !(images|membersdownload)$
RewriteCond %{REQUEST_FILENAME} !^C:/xampp/htdocs/store/
RewriteRule ^(.*)$ %{HTTP_HOST}$1 [C]
RewriteRule ^(.*)\.mydomain\.com/.* /index.php?a=item&detail=$1 [QSA,L]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain\.com$ [NC]
RewriteRule ^purchase /index.php?a=item&detail=%1&buy
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain\.com$ [NC]
RewriteRule ^images /index.php?a=item&detail=%1&img
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain\.com$ [NC]
RewriteRule ^seller /index.php?a=item&detail=%1&pub
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain\.com$ [NC]
RewriteRule ^membersdownload /index.php?a=item&detail=%1&dwn
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain\.com$ [NC]
RewriteRule ^usersreviews /index.php?a=item&detail=%1&rev
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain\.com$ [NC]
RewriteRule ^fraudreport /index.php?a=item&detail=%1&awr
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain\.com$ [NC]
RewriteRule ^usersreview-(.*) /index.php?a=item&detail=%1&usersreview=$1}


Thanks.
bobmaine
 
Posts: 2
Joined: Thu Jun 11, 2009 9:11 am

Postby richardk » Thu Jun 11, 2009 2:51 pm

The rules rewrite to /index.php not /store/index.php (or ./index.php (relative)).

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(example\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !(images|membersdownload)$
RewriteCond %{REQUEST_FILENAME} !^C:/xampp/htdocs/store/
RewriteRule .* ./index.php?a=item&detail=%1 [QSA,L]

RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^purchase ./index.php?a=item&detail=%1&buy [QSA,L]

RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^images ./index.php?a=item&detail=%1&img [QSA,L]

RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^seller ./index.php?a=item&detail=%1&pub [QSA,L]

RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^membersdownload ./index.php?a=item&detail=%1&dwn [QSA,L]

RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^usersreviews ./index.php?a=item&detail=%1&rev [QSA,L]

RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^fraudreport ./index.php?a=item&detail=%1&awr [QSA,L]

RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^usersreview-(.*) ./index.php?a=item&detail=%1&usersreview=$1} [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby bobmaine » Thu Jun 11, 2009 3:21 pm

Wow you are the best Rich. Code working great.Thanks for your fix.
bobmaine
 
Posts: 2
Joined: Thu Jun 11, 2009 9:11 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 18 guests

cron