mod_rewrite problem from / to /public_html/

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

mod_rewrite problem from / to /public_html/

Post by tecktalkcm0391 »

I have a .htaccess file in /home/ of my site.... my site's html is in /home/public_html/

Whenever I do a rewrite like
RewriteRule ^img([A-Za-z0-9]+).image/$ img.php?picid=$1 [NC]

It goes from site.com/img4.image/ to site.com/public_html/img4.image

How can I fix this?
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Does rewrite start from $0 or $1? If the latter you might want to try $2.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$0 would be the entire match, $1 is the first captured group, $2 is the second and so forth...
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

I'm not familiar with RewriteRule, but I do some work with servers and it sounds like your host made "public_html" your root... I guess you'd have to forcefully go back a directory if you have permissions to it.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

To fix it simply reference the proper location in the second part of the rule... you simply reference img.php without indicating what folder it's in... so naturally it assumes the working directory which is why it's returning /home/

eg. /home/public_html/img.php

Be sure to also use the flag QSA and if it's the only or last rule, use the flag L.
Post Reply