Link to home
Start Free TrialLog in
Avatar of bradnoble
bradnoble

asked on

mod_rewrite rewriterule relative links

Hi EE,

I'm using mod_rewrite and rewrite rule for user-friendly URLs, and it's working fine.  The only time it fails me is if the user accidentally includes a trailing slash in the URL.

Here's my /.htaccess:

Options FollowSymLinks
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([-.a-zA-Z_0-9]+)/?$ /page.php?pagealias=$1 [NC]

This says, if URL contains a file or directory that exists, go there.  If not, compile into a variable and send to page.php (which uses the querystring $1 to pull dynamic content).

If the user enters, http://www.site.com/fire-protection
the rewriterule works, and the relative links for things like images and css files work fine.

If the user enters, http://www.site.com/fire-protection/
the rewriterule works, but the relative links no longer work.  

Can i eliminate the trailing slash and then do the rewriterule?  Or, is there some way to easily create relative links as absolute links, without hard coding each link?
ASKER CERTIFIED SOLUTION
Avatar of TomDavidson
TomDavidson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bradnoble
bradnoble

ASKER

Thanks for your help.  I simply made my links relative and that worked fine!
WHOOPS!  I mean, i simply made the links absolute!