Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite and relative linking

         

willroy

2:23 pm on Jan 31, 2008 (gmt 0)

10+ Year Member



Hello,

I use mod_rewrite to create a virtual directory structure:

RewriteEngine on
# Add trailing slash if missing
RewriteCond $1 ^[^\.]+[^/]$
RewriteRule (.*) [%{HTTP_HOST}...] [R=301,L]
#
# Internally rewrite SEO-friendly URLs to script
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ index.php?m=$1&p=$2&s=$3 [L]
RewriteRule ^([^/]+)/([^/]+)/$ index.php?m=$1&p=$2 [L]
RewriteRule ^([^/]+)/$ index.php?m=$1 [L]

With the above rules, in order to relatively link, I have to insert the "../" when I want to go back up a level i.e. if the folder structure is example.com/section/products/ in order to link to a root folder directory I would have to use <a href="../../differentsection/products/"> otherwise without using the "../../" it would append it to the current url like this: example.com/section/products/differentsection/products

Now I have seem a number of other websites which work differently. i.e. if they were on page example.com/section/products they would simply use <a href="differentsection/products/">

I would really appreciate some help on this as it would save me hassle with lot's of things! (I currently use a loop function which add's the correct amount of "../"'s depending on current folder depth in url!)

Thanks!

Will

jdMorgan

8:03 pm on Jan 31, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Consider using a fixed path -- a server-relative link:

<a href="/<path>/differentsection/products/">

Or use a canonical address and be done with it:

<a href="http://example.com/<path>/differentsection/products/">

Alternately, you can add yet more rewriterules to normalize these requests to the proper directory. But beware, as this can cause duplicate content issues.

Jim