HOME       >>       Programming

Css Not Working (Clean Url)


RyosukeGunma

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?


web_designer

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.

Parubilla

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.


vhortex

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 href="/comments.css" type="text/css" media="screen" />

or even putting the full URL like this
<link 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.

Quatrux

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.

RyosukeGunma

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.


angelacat

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.



REGISTER GET FREE HOSTING

Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved.