1

I am using following mod_rewrite rule:

  **RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f
    RewriteRule ^(.*)$ $1.php [L]**

to get clean url such as

  www.myweb.com/login

from

 www.myweb.com/login.php

I am using another rewrite rule

**RewriteRule ^itemdetail/([0-9]+)/?$ itemdetail.php?itemid=$1 [NC,L]**

to get

 www.myweb.com/itemdetail/100008

from

 www.myweb.com/itemdetail?itemid=100008.

This works fine but there is one problem. This rewrite rule add a subdomain on every link. for example. if the link to css file is text.css now the link to this css file is itemdetail/text.css. The link to home page is now www.myweb.com/itemdetail/home instead of www.myweb.com/home. What am I doing wrong here. Please help.

Hari
  • 31
  • 7

1 Answers1

0

This rewrite rule add a subdomain on every link. for example. if the link to css file is text.css now the link to this css file is itemdetail/text.css. The link to home page is now www.myweb.com/itemdetail/home instead of www.myweb.com/home. What am I doing wrong here.

You can do one of two things to deal with this, either add this to the header of your itemdetail.php pages (inside the <head> </head> tags):

<base href="/">

Or you can change your css links from relative to absolute URLs by adding a leading /, example:

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

Otherwise, you could try adding rewrite rules to un-write the css links, but that's usually a really bad idea, as it'll break css in subdirectories when you are intentionally using them:

RewriteRule ^itemdetail/(.*?)\.css$ /$1.css [L]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • does IE support ? – Hari Sep 18 '12 at 19:35
  • @Hari there are peculiar bugs involving the `` tag and different versions of IE: http://stackoverflow.com/a/8973975/851273 Also I think older versions of IE (6 maybe?) may not support it at all. – Jon Lin Sep 18 '12 at 19:40
  • Thank you. Apparently IE requires whole href than just "/". – Hari Sep 19 '12 at 20:21