Forum Moderators: phranque
RewriteEngine on
#
# Externally redirect to add missing trailing slash if URL path does not contain a period or end with a slash
RewriteCond $1 ^[^\.]+[^/]$
RewriteRule (.*) http://%{HTTP_HOST}/jbiv8/$1/ [R=301,L]
#
# Internally rewrite SEO-friendly URLs to script
RewriteCond $1 !^images
RewriteCond $1 !^cmsadmin
RewriteRule ^([^/]+)/$ index.php?m=$1 [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ index.php?m=$1&p=$2&s=$3 [L]
RewriteRule ^([^/]+)/([^/]+)/$ index.php?m=$1&p=$2 [L]
RewriteRule ^([^/]+)/$ index.php?m=$1 [L]
Now this means that in order to keep my links relative then I have to use a php loop using the folder structure in the current url and append "../" to the beginning of my hyerlinks.
Now I would rather not have to do this and thought it was the only way until I was looking at this page for example: http://www.example.com/emergency-repairs/pest-control.
Looking at the source code for that page you can see they don't have any "../" but instead, if they want to link to another directory then they link to "/emergency-repairs/windows-and-doors" Where as if that was my site I would have to do "../windows-and-doors".
So can anyone tell me is there a code which can do this for me? Is it do to with appending a link to the current url?
Any help appreciated, Will
[edited by: jatar_k at 2:45 pm (utc) on Jan. 18, 2008]
[edit reason: Please use example.com]
[edited by: jdMorgan at 3:49 pm (utc) on Jan. 18, 2008]
[edit reason] de-linked [/edit]
...then they link to "/emergency-repairs/windows-and-doors" Where as if that was my site I would have to do "../windows-and-doors".
This is not strictly true. The link format they are using is a "server-rooted relative path" and should work fine on your server, although it probably won't work on your development machine unless you are running a server on your development machine as well.
The browser takes the server-rooted relative links, prepends the current domain name (from its address bar), and requests the resulting URL -- To be clear, it is the client --the browser or search engine robot) tht resolves relative links to absolute URLs.
If you do not wish to use server-rooted links, then the alternative is to rewrite all requests for 'shared objects' to the correct directory. You will need to write RewriteRule patterns to detect requests for those shared objects, strip off the extra URL-path prefix (remove your 'fake' directory levels which are really your query parameters), and rewrite to the correct file location. The problem with this is that it creates multiple URLs for the same object, and can cause trouble, for example, if you care about image search ranking.
Jim