Synyster Synyster - 2 months ago 9
Apache Configuration Question

rewriting URL seem to be written wrong

I just realised that some of my rewritten urls stopped working. I am unaware of why.

Here is my rewrite file

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^forums/([^/]*)/locate/([^/]*)/$ /forums.php?page=$1&tlocate=$2

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^changelogs/([^/]*)/$ /index.php?page=$1

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^forums/$ /forums.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/$ /forums.php?page=$1

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^forums/action/([^/]*)/$ /forums.php?page=$1

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^forums/([^/]*)/section/([^/]*)/$ /forums.php?page=$1&sectionid=$2

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^register/([^/]*)/$ /register.php?page=$1

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^account/([^/]*)/$ /account-page.php?page=$1

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^about-us/$ /about.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^forums/([^/]*)/topic/([^/]*)/$ /forums.php?page=$1&topic=$2 [L]

ErrorDocument 400 /error.php
ErrorDocument 401 /error.php
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php


If i went to www.localhost/account/

It would just send me to www.localhost/forums/

So i downloaded mozilla to see if my htaccess stopped working. The css didnt work there. I then went to a website to check my code and it complained about the line

RewriteRule ^about-us/$ /about.php


On that line, i tried to rewrite www.localhost/about.php
into www.localhost/about-us/

without any success. What is it that i'm doing wrong that causes this issue?

Answer

You can use in your .htaccess:

# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^forums/([^/]*)/locate/([^/]*)/$ /forums.php?page=$1&tlocate=$2 [L]
RewriteRule ^changelogs/([^/]*)/$ /index.php?page=$1 [L]
RewriteRule ^forums/$ /forums.php [L]
RewriteRule ^forums/action/([^/]*)/$ /forums.php?page=$1 [L]
RewriteRule ^forums/([^/]*)/section/([^/]*)/$ /forums.php?page=$1&sectionid=$2 [L]
RewriteRule ^register/([^/]*)/$ /register.php?page=$1 [L]
RewriteRule ^account/([^/]*)/$ /account-page.php?page=$1 [L]
RewriteRule ^about-us/$ /about.php [L]
RewriteRule ^forums/([^/]*)/topic/([^/]*)/$ /forums.php?page=$1&topic=$2 [L]
RewriteRule ^([^/]*)/$ /forums.php?page=$1 [L]

ErrorDocument 400   /error.php
ErrorDocument 401   /error.php
ErrorDocument 403   /error.php
ErrorDocument 404   /error.php
ErrorDocument 500   /error.php

And add this code in your about.php HTML code:

<base href="/">

Because you change the root (for css and others relatives) with your about-us/ link.