Jump to content
xisto Community
Sign in to follow this  
RyosukeGunma

Css Not Working (Clean Url)

Recommended Posts

Hi, I decided to try some clean url (mod_rewrite) in my project. The clean url works but the CSS and images could not be found.e.g: From index.php?id=home&idPage=1 to /home/1 . My CSS was redirect to /home/css/styles.css and not css/styles.cssIs there any way to fix that?

Share this post


Link to post
Share on other sites

Hi, I decided to try some clean url (mod_rewrite) in my project. The clean url works but the CSS and images could not be found.
e.g: From index.php?id=home&idPage=1 to /home/1 . My CSS was redirect to /home/css/styles.css and not css/styles.css

Is there any way to fix that?


hi,
i did a quick search on google and came up with this. mod_rewrite should ignore some directories (like images and css directories). so try this code and post here to know if it worked for you

RewriteCond %{REQUEST_URI} ^/(cgi-bin|css|images)/?.

or try this one

RewriteRule ^(|css|images|) - [L]

hope you luck.

Share this post


Link to post
Share on other sites

Same happen to me once, and it was like a glitch the only solution I could find was to reinstall (I believe you are talking about Joomla!), the latest version and it worked.And it also happened to me, that when I put different languages, the css would also stop working.

Share this post


Link to post
Share on other sites

The best way and fastest method to solve it is to append / on the CSS path. A mod_rewrite rule when properly written will ignore existing files and directories while HTML css will be search on the rewritten URL.

Example: A mod rewritten URL like this

http://mynewserver.com/mycategory/myatriclename

Will have its CSS search at
http://mynewserver.com/mycategory/myatriclename/cssfilename.css

Appending a / on the CSS path like this
<link rel="stylesheet" href="/comments.css" type="text/css" media="screen" />

or even putting the full URL like this
<link rel="stylesheet" href="http://mynewserver.com/comments.css" type="text/css" media="screen" />
always fixes the problem. For CSS images, do take note that they are being read relative to the stylesheet folder.

Since you are doing some mod_rewrite and .htaccess modification, maybe this article can add some help in the future Essential .htaccess Commands, if the link is useful to you, I will appreciate dropping a comment. :blush:

Share this post


Link to post
Share on other sites

Another way to do it, even though it usually is a less smooth way is to make one string.

The rewrite rule could look something like this:

<IfModule mod_rewrite.c>    RewriteEngine On    RewriteCond %{REQUEST_FILENAME} !-d    RewriteCond %{REQUEST_FILENAME} !-f    RewriteRule ^(.*)$ index.php?mygetkey=$1 [QSA,L]</IfModule>

and you would have nice clean URL, but in PHP you could access the string through $_GET['mygetkey']; which would have all the line, for example 'home/category/article/id' but in this case you would need to get your parameters yourself, usually I just create a navigation class which makes everything simple on later usage.

Mod rewrite is really powerful, there are plenty ways to do things, just you need to find the solution you need. :)

Share this post


Link to post
Share on other sites

Thanks everyone. I have tried RewriteRule ^(|css|images|) - [L] and it didn't work. I managed to get the CSS working by putting a slash / on every src, which is a bit long but still worth it.Does anyone know if it's possible for mod rewrite to get access a MySQL table and get data? I was thinking to put a custom fieldname in a MySQL table so we could put our own clean URL. A lot of CMS like Joomla can put their own custom URL.

Share this post


Link to post
Share on other sites

I have experienced this issue yesterday.With clean-urls enabled I have discovered that if any drupal webpage has more than one arg in the url, then images linked relative to the site don't appear.When clean-urls are disabled, the images work on every pages. If you get any ideas, please share with us.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.