Page 1 of 1
mod rewrite -- again
Posted: Tue Oct 11, 2005 10:25 pm
by s.dot
Is there any way to do a mod rewrite so apache doesn't think it's in a different directory?
for example.. if I do
Code: Select all
rewrite rule ^photos/(username)$ page.php?u=$1
apparently it thinks it should be in the photos/ directory
I tried to rewrite to ../page.php (no luck)
and
http://www.domain.com/page.php (no luck)
Posted: Wed Oct 12, 2005 10:43 am
by pickle
Posted: Wed Oct 12, 2005 10:48 am
by redmonkey
RewriteBase
Posted: Wed Oct 12, 2005 12:36 pm
by Chris Corbyn
redmonkey wrote:RewriteBase
Or just put the leading forward slash on the right hand side
Code: Select all
RewriteRule ^photos/(.*)$ /page.php?u=$1
Posted: Wed Oct 12, 2005 1:18 pm
by redmonkey
In this particular case... correct

Posted: Wed Oct 12, 2005 3:41 pm
by s.dot
adding the forward slash produced the same result.
So I'm looking into rewrite base.
Would it look something like this?
(consider I do not have a physical /photos directory)
Code: Select all
RewriteEngine On
RewriteBase /photos
RewriteRule ^photos/(.*)$ page.php?$u=1
Posted: Wed Oct 12, 2005 10:10 pm
by s.dot
Using this code in an empty photos/ diretory
Code: Select all
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9_-]+)(/)?$ /albums.php?u=$1
Works. However, all of my links are acting as if the page is in the photos/ dir. IE what should be domain.com/page.php is now domain.com/photos/page.php .. Is it possible to make it so it doesn't do that =/
Posted: Fri Oct 14, 2005 2:34 am
by s.dot
*bump*

Posted: Fri Oct 14, 2005 9:43 am
by redmonkey
The issue is not with mod_rewrite, it is with your browser and is expected behaviour.
It's your broswer that works out any relative linking. You have to remember that as far as your browser is concerned it's looking at yoursite.com/photos
As a result any relative links on your page will be assumed (quite rightly) to have a base of yoursite.com/photos.
You should use absolute links from the HTTP root.
Posted: Fri Oct 14, 2005 10:53 am
by phpdevuk
dunno if this helps but I found slapping <BASE href="
http://www.mysite.com"> at the top of the page sorts out bugs with links that should be from top level rather than a rewritten address.
Posted: Sat Oct 15, 2005 4:36 am
by s.dot
thanks, the BASE HREF sorted things out nicely. now will this cause a problem if I throw it in my header file (thats included on all pages)
I don't have any other directories other than the main one (that pages are in anyways)
I just want to be cautious =)