I have the following Short-hand for a user profile url
RewriteRule ^(\\w+)/?$ ./profile.php?name_of_user=$1
The site is styled with the app
Try this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.(gif|jpg|png|jpeg|css|js|swf)$ /public/$1.$2 [L,NC]
# Removes index.php from ExpressionEngine URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L,QSA]
</IfModule>
the easiest way to fix this is to specify the full path to your CSS file in the <head>
of the HTML file.
If your mod_rewrite rule is modifying the path to where your CSS file is, you'd also want to place this before your RewriteRule
:
RewriteCond %{REQUEST_FILENAME} !-f
This makes sure that the request doesn't match a file before rewriting it.
I had the same problem and I've solved it with the following code. Not the best solution but it works.
RewriteRule ^(something/)$ something [R]
RewriteRule ^(something)$ index.php?page=$1 [L]
Try to set right basedir at your html documents head section:
<head>
<base href="http://example.com/">
<head>
Then any extra slashes (/) at your .htaccess rules won't change exterial sources path in your html documents. The following rule
RewriteEngine On
RewriteBase /
RewriteRule ^(\w+)/?$ ./profile.php?name_of_user=$1
won't make this behaviour with <base href="http://example.com/">
at document's <head>
.
It will works fine, especially for relative site file structures.
The easiest way is to use <base href="site url here">
, and this should be soon after the opening HTML head
tag.
Site url needs to start with http or https; if you are on localhost then use http, for example
http://localhost/road/
When your page URL is example.com/name_of_user/
, loading of resource css/js/images may cause problems if your HTML page is using relative paths for these resources. It is because browser resolves resource URLs using current URL.
So for example if a style tag is:
<link rel="stylesheet" type="text/css" href="static/style.css">
and your current page URL is:
http://example.com/name_of_user/
Then browser will resolve css URL as as example.com/name_of_user/static/style.css
instead of example.com/static/style.css
. This will cause 404 for resource URLs and your page will be displayed without any style, scripts and images.
You can solve this problem using one of the following ways:
Use absolute path in your css, js, images files rather than a relative one. Which means you have to make sure path of these files start either with http://
or a slash /
.
Otherwise You can add this just below <head>
section of your page's HTML:
<base href="/" />
so that every relative URL is resolved from that base URL and not from the current page's URL.