homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Mod-Rewrite - Using usual path to css/js/images

Msg#: 4615988 posted 7:54 pm on Oct 10, 2013 (gmt 0)

I have some code to make
www.domain.com/state/statename/folder/index.php?name=name to statename.name.domain.com. These are my codes:

RewriteEngine On

RewriteCond %{REQUEST_URI} !\.(jpe?g|gif|bmp|png|tiff|css|js)$ [NC]

RewriteCond %{HTTP_HOST} ^([^.]+)\.([^.]+)\.(domain\.com)$ [NC]
RewriteRule !^state/ /state/%1/folder/index.php?name=%2&page=%{REQUEST_URI} [L,NC]

The problem is now I have to use full url to link my css, js and image files. Also, one of the plugins in my code (AjaxLoader) Couldn't use full url to load a page in a div. Relative path such as (path/filepath.ext) does not work.

So, is there anyway to use usual path (path/filepath.ext)?

Thank you very much. Really appreciate your help.



WebmasterWorld Administrator 5+ Year Member

Msg#: 4615988 posted 10:14 pm on Oct 10, 2013 (gmt 0)

Welcome to WebmasterWorld, redzwanlatif !

You are serving scripts from your internal path as subdomain, but you are not applying this to images, css etc. Hence to the outside world they are on a different host and you need to fully qualify it with host name, as you have found out.

If you want to keep your paths from root only (e.g. src="/some-path") for your jpg, css etc, you would need another rule just for these files that rewrites the request to the physical location of your jpg, css etc.

So to the outside world they would be served under whatever the subdomain you have, allowing you to have paths in HTML absolute from root, but physically they would be picked up from the same place on the server for all subdomains.


Msg#: 4615988 posted 5:02 am on Oct 11, 2013 (gmt 0)

How to write the another rule that rewrites the request to the physical location of the files? Thanks :D. Still a beginner in mod-rewrite


WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Msg#: 4615988 posted 9:02 am on Oct 11, 2013 (gmt 0)

Where do the non-page files really live? Does each /state/ subdirectory have its own set of images, CSS and so on, or is there yet another directory that holds all of them? Before you can write a rule, you need to lay out in English exactly what you want to have happen.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved