...

View Full Version : mod_rewrite problem



devinmaking
10-06-2011, 04:18 PM
I originally posted this in the php section but i realise this was the wrong area.

I have a problem.

I am no expert in mod rewrite and i am only just starting to use it to be honest.

Anyway the problem i have is when ever a second subdomain is used the css,images,js and all other type of files are not showing.

For instance i am trying to get:

www.domain.com/edit-blog/username/blogid

out of this

www.domain.com/users/add-blog.php?username=$username&mode=edit&id=$id

The code i am using is as follows:


RewriteRule ^edit-blog/([A-Za-z0-9-]+)/([0-9]+)$ users/add-blog.php?username=$1&mode=edit&id=$2 [L]

I have set the

RewriteBase /

but if i have a single folder like this

www.domain.com/edit-blog/username it works with no errors but as soon as i add the /bligid at the end of it the url works but the images, js, css etc are not working.

Any ideas?

Cags
10-06-2011, 08:26 PM
What do the src tags of the images / js files etc. look like? Presumably they are relative paths, when requesting assets for a page the relative paths will be relative to the current URL, if you are using pretty URLs that are multiple 'directories' deep (i.e. you have slashes in them) the assets will be searched for relative to this point.

So let's say we have an index.php file in your server root, along with a js folder which contains jquery.js. In index.php you have <script src="js/jquery.js"></script>, this will work just fine, requesting the javascript file from /js/jquery.js but if you rewrite the URL /multi-level/path-url to index.php, It will attempt to load the javascript file from /multi-level/js/jquery.js, which obviously wont exist.

Long story short, use path relative to root (start with a forward slash), or absolute paths.

devinmaking
10-06-2011, 09:13 PM
What do the src tags of the images / js files etc. look like? Presumably they are relative paths, when requesting assets for a page the relative paths will be relative to the current URL, if you are using pretty URLs that are multiple 'directories' deep (i.e. you have slashes in them) the assets will be searched for relative to this point.

So let's say we have an index.php file in your server root, along with a js folder which contains jquery.js. In index.php you have <script src="js/jquery.js"></script>, this will work just fine, requesting the javascript file from /js/jquery.js but if you rewrite the URL /multi-level/path-url to index.php, It will attempt to load the javascript file from /multi-level/js/jquery.js, which obviously wont exist.

Long story short, use path relative to root (start with a forward slash), or absolute paths.

the paths are all set to ../ on these pages.

Should i do absolute as in www.domain.com/js/jsfiles.js etc etc

Inigoesdr
10-07-2011, 12:16 AM
the paths are all set to ../ on these pages.

Should i do absolute as in www.domain.com/js/jsfiles.js etc etc

Yeah, or root-relative like this: /js/jsfiles.js



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum