3

I am trying to make some changes to .htaccess file of a site. I have searched all over the web, but I cant find a clear solution for that, or there is possibility that I have got it wrong. So here we are are:


RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule   ^/$  /e/www/  [R]
RewriteRule ^news$ /news.php
RewriteRule ^news$ /news.php
RewriteRule ^resources$ /resources.php
RewriteRule ^lexicon$ /lexicon.php
RewriteRule ^contacts$ /contacts.php
RewriteRule ^analytics$ /analytics.php
RewriteRule ^([0-9]+)-([0-9]+)-([0-9]+)-(.*)$ /news.php?yy=$1&mm=$2&dd=$3&alias=$4
RewriteRule ^resources$ /contacts.php
RewriteRule ^articles_search$ /articles_search.php
RewriteRule ^articles_data_search$ /articles_data_search.php
RewriteRule ^profile/([0-9]+)&commit=(.*)$ /profile.php?id=$1&commit=$2
RewriteRule ^profile/(.*)&commit=(.*)$ /profile.php?alias=$1&commit=$2

At last 2 rows, i am trying to have a result from this:

www.example.com/profile.php?alias=kokazani&commit=Edit

to this:

www.example.com/profile/kokazani&commit=Edit

The problem now is the wrong path of css and js files. I need a solution, or a better approach of rewriting rules. I think that a solution ,maybe, is to rewrite everything like css/blabla.css to root directory/css/blabla.css, but if there a standard-solution foro this problem, i would like to know :)

Thanks in advance.

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
kokazani
  • 213
  • 2
  • 13

2 Answers2

3

There are 2 possible (simple) solutions:

  • Use absolute paths for your CSS files (/include/css/style.css etc)
  • Use HTML's <base> element to set the correct base URL for relative URLs to follow (rather then the directory of the document which is altered by Apache).
Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
  • I just use the solution. All clean and clear. If i have any other problem with that, i ll poke you :) Thanks again. – kokazani Nov 08 '11 at 18:55
1

My approach would be (as suggested by Truth) using absolute paths. If this is not possible, you could use:

RewriteRule ^(.+)/css/(.*)$ /css/$2

But be warned: This means the client (browser) will end up getting and caching multiple copies of the same file because it is fetching it (as far as it can see) from different paths. Therefore you lose the advantage of client-side stylesheet caching.

daiscog
  • 11,441
  • 6
  • 50
  • 62