0

I was wondering if anyone could help? Basically I've got a set of mod_rewrite rules and they all work well except if I put a trailing slash at the end of the URL it goes crazy. Still show's the page (sometimes) except all of the CSS, JS, etc is not included because the path messes up when there's a trailing slash. The only way to solve it is to put a BASE tag which I would really like to avoid as it brings it's own set of issues. Is there something wrong with my htaccess? I just need it to ignore the trailing slashes.

Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^resetpassword/([^/.]+)/?$ resetPassword.php?resetCode=$1 [L] RewriteRule ^activate/([^/.]+)/?$ activateAccount.php?ACTCode=$1 [L] RewriteRule ^dashboard/?$ dashboard.php [NC,L] RewriteRule ^login/?$ login.php [NC,L] RewriteRule ^register/?$ register.php [NC,L] RewriteRule ^messages/inbox/??$ messagesInbox.php [NC,L] RewriteRule ^messages/archive/??$ messagesArchive.php [NC,L] RewriteRule ^messages/??$ messagesInbox.php [NC,L] 

1 Answer 1

1

There's likely not a good fix for this because you'll be switching "directory" levels in any case (like in messages/inbox).

The most common solution is to either use an absolute path to reference CSS, images etc.:

<link rel="stylesheet" href="/css/styles.css"> 

or to have a PHP variable containing the web root:

<link rel="stylesheet" href="<? echo $webroot; ?>/css/styles.css"> 

Both these approaches are vastly better than using a base tag, or doing some .htaccess-based redirection shenanigans.

Sign up to request clarification or add additional context in comments.

2 Comments

Agreed, well the files are actually in root, it's just looking like directories to make it look "pretty". I've put an absolute path for all includes but for some reason they freak out when I put a trailing slash. Example: URL localhost/project/login - WORKS URL localhost/project/login/ - ALL includes have now been changed to look in the LOGIN directory
Then something's wrong with the way you do it. Can you show a code example?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.