Url rewrites messes css / js up

what i am trying to achieve is

domain.com/register/free

which would be

domain.com/register.php?type=free

When I go go domain.com/register

, the page loads fine, but if I put in the next part /free

, it can't find the css or js images, etc. Not too sure where I went wrong, but this is my .htaccess file

RewriteRule ^register$ register.php
RewriteRule ^register/$ register.php

RewriteRule ^register/([a-zA-Z0-9\-\_]+)$ register.php?type=$1

      

+3


source to share


1 answer


First, you can improve your rules.

Options -MultiViews

RewriteEngine On
RewriteBase /

RewriteRule ^register/?$ register.php [L]
RewriteRule ^register/([a-zA-Z0-9_-]+)$ register.php?type=$1 [L]

      

Then, since you are creating a virtual folder due to your rule ( /register/

) and you are using relative paths (instead of absolute ), your links are no longer good.



Two parameters (both using absolute paths):

  • add a slash for all your css links (and js, img, etc.).
    for example: href="/css/style.css"

    instead ofhref="css/style.css"

  • add this tag right after <head>

    in all your interested pages: <base href="/">

    (this will keep you from replacing every link one by one)
+1


source







All Articles