mod rewrite -- again

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

mod rewrite -- again

Post 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 :P

I tried to rewrite to ../page.php (no luck)
and http://www.domain.com/page.php (no luck)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

RewriteBase
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

In this particular case... correct :)
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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 =/
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

*bump* :)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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.
User avatar
phpdevuk
Forum Contributor
Posts: 220
Joined: Mon Jul 04, 2005 5:31 am
Location: UK
Contact:

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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 =)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply