Search code examples
css.htaccesseasyphp

reference when rewriting an URL


I'd like to transform an URL like this http://www.mydomain.com/it/archive.php=321123 in one like the following http://www.mydomain.com/it/R/321123 In a book I found something useful with few practice I get the following

RewriteEngine On
RewriteRule ^R/(.*) archive.php?$1 [PT]

which work properly. The problem is that any ref inside of the code like

<link rel="stylesheet" type="text/css" href="css/layout.css" />

is trasnformed into

<link rel="stylesheet" type="text/css" href="www.mydomain.com/it/R/css/layout.css" />

The R folder does't exist in the reality so it doesn't contain any css file, all the css files are stored into the folder http://www.mydoman.com/it/css. The Chrome developers utility give me the following: Resouce interpreted as Stylesheet but transferred with MIME type text/html: "http://www.mydomain.com/it/R/css/style.css".

Is possibile to change the address but mantain the same references of the original page inside of the page. I could write

<link rel="stylesheet" type="text/css" href="http://www.mydomain.com/it/css/layout.css" />

but this should not work when I am working offline with EasyPHP.

PS: I'd like to put the .htaccess file into the http://www.mydomain.com/it folder so it will affect only the it language part.

Thanks!


Solution

  • You can add this to the header of the pages:

    <base href="/it/">
    

    And that should make it so the relative URI paths (e.g. "css/layout.css") don't get mixed up with the /R/ from the rewriting.

    If that's not possible, you could try adding extra rules to make the css work:

    RewriteRule ^R/css/(.*)$ css/$1 [L]