Htaccess + modrewrite problem

I want each user to have a profile URL:

www.example.com/username

I created this htaccess:

RewriteEngine on
RewriteRule ([^/]+) profile.php?username=$1 [L]

but I get an error with css and js files.

what do i need to write in htaccess?

+3
source share
2 answers

You should, in general, exclude all real files and directories, as this will handle css / js / images / whatever you want to serve:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ profile.php?username=$1 [L]
+3
source

Exclue js and css c RewriteCond. I think this should do:

RewriteEngine On
RewriteCond %{REQUEST_URI} ! \.(js|css)$ [NC]
RewriteRule ([^/]+) profile.php?username=$1 [L]

If you have images, add their extensions

RewriteCond %{REQUEST_URI} ! \.(js|css|jpg|gif|ico|png|whatever)$ [NC]
+2
source

All Articles