Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Css Not Working (Clean Url)


6 replies to this topic

#1 RyosukeGunma

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 11 posts

Posted 27 January 2011 - 01:15 AM

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?

#2 web_designer

    "french rose sparkle under moonlight"...do you believe in the magic of moonlight??!!...

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPip
  • 1,385 posts
  • Gender:Female
  • Location:US, CA
  • Interests:internet and the web
    reading books
    sport
    watching tv series
    drawings and art
  • myCENT:12.10
  • Spam Patrol

Posted 27 January 2011 - 08:18 AM

View PostRyosukeGunma, on 27 January 2011 - 01:15 AM, said:

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.

#3 Parubilla

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 215 posts
  • Gender:Female
  • myCENT:56.63

Posted 30 January 2011 - 07:33 PM

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.

#4 vhortex

    Member [Level 3]

  • Kontributors
  • PipPipPipPipPipPip
  • 97 posts
  • Gender:Male
  • myCENT:9.31

Posted 03 February 2011 - 07:39 AM

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:

#5 Quatrux

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 605 posts
  • Gender:Male
  • Location:Lithuania, Vilnius
  • Interests:Programming
  • myCENT:49.19

Posted 07 February 2011 - 08:38 AM

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. :)

#6 RyosukeGunma

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 11 posts

Posted 24 February 2011 - 02:30 AM

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.

#7 angelacat

    Newbie

  • Kontributors
  • Pip
  • 7 posts
  • Gender:Male
  • Interests:watch movies, surf Interent, get open resources on web

Posted 04 July 2011 - 05:54 AM

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.




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users