Problema del subdirectorio .htacces css / js

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

a esto:

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

El problema ahora es el 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 :)

Gracias de antemano.

preguntado el 08 de noviembre de 11 a las 18:11

Code formatting is done with 4 spaces indention before each line of code. See the FAQ y ayuda de edición -

Just a quick question - are you sure you want /profile/kokazani&commit=Edit y no /profile/kokazani?commit=Edit? -

what is the benefit of ? instead of & usage? -

2 Respuestas

There are 2 possible (simple) solutions:

  • Use absolute paths for your CSS files (/include/css/style.css etc.)
  • Usa HTML <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).

respondido 08 nov., 11:22

I just use the <base> solution. All clean and clear. If i have any other problem with that, i ll poke you :) Thanks again. - kokazani

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.

respondido 08 nov., 11:22

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.