Welcome to WebmasterWorld Guest from 54.146.194.42

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

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

     
7:54 pm on Oct 10, 2013 (gmt 0)

New User

joined:Oct 10, 2013
posts: 2
votes: 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.
10:14 pm on Oct 10, 2013 (gmt 0)

Moderator from GB 

WebmasterWorld Administrator 5+ Year Member Top Contributors Of The Month

joined:Apr 30, 2008
posts:2507
votes: 138


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.
5:02 am on Oct 11, 2013 (gmt 0)

New User

joined:Oct 10, 2013
posts: 2
votes: 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
9:02 am on Oct 11, 2013 (gmt 0)

Senior Member from US 

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

joined:Apr 9, 2011
posts:12702
votes: 244


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.