Htaccess causing broken links


When I use my htaccess to make my links more SEO friendly, it kills my pages, and doesn’t include CSS files etc properly.

Example: - Works - Doesn’t

Looking at the source code its because it begins to look for pages at /forum/ which doesn’t exist.

This is my htaccess file:

ErrorDocument 404 /index.php?page=error

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\\.insidercharts\\.com$
RewriteRule .?{REQUEST_URI} [L,R=301]

RewriteRule ^forums$ /forum.php
RewriteRule ^forums/([0-9]+)/([0-9]+)/(.*?).html$ /forum.php?page=thread&pid=$1&p=$2
RewriteRule ^forums/([0-9]+)/([a-zA-Z0-9_-]+)$ /forum.php?page=view&fid=$1

Besides hard coding all my links, is there a better way to solve this issue using htaccess?

Sorry if this topic has been covered

Take a look at the section “Relative Links Are Missing!” on :slight_smile:

Normally I would give comments about your current .htaccess here, things you can fix, etc, but your .htaccess looks so good I really don’t have anything to say about it :slight_smile:


forums/ is a directory which will require Apache to go off to find the DirectoryIndex so that’s not a smart thing to do (allow both forum and forum/). I prefer forum/ but your .htaccess only accommodates the forum version. On the other hand, it’s apparent that your forum is in the DocumentRoot so using the forum/ version places you one directory level deeper into your website which your relative links cannot handle. If you think you need to, redirect forum/ to forum with a 301 then redirect (as you’ve already done) forum to forum.php.

As Rémon pointed out, though, you can’t redirect both to the DirectoryIndex as the visitors’ browsers will not know which directory level to look to for your relative links. Apache is good but it’s not clairvoyant!