Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-06-2011, 03:18 PM   PM User | #1
devinmaking
Regular Coder

 
Join Date: Oct 2011
Posts: 236
Thanks: 11
Thanked 5 Times in 5 Posts
devinmaking has a little shameless behaviour in the past
mod_rewrite problem

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:

PHP Code:
RewriteRule ^edit-blog/([A-Za-z0-9-]+)/([0-9]+)$ users/add-blog.php?username=$1&mode=edit&id=$[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?
devinmaking is offline   Reply With Quote
Old 10-06-2011, 07:26 PM   PM User | #2
Cags
New Coder

 
Join Date: Jul 2011
Posts: 67
Thanks: 0
Thanked 13 Times in 13 Posts
Cags is an unknown quantity at this point
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.
Cags is offline   Reply With Quote
Old 10-06-2011, 08:13 PM   PM User | #3
devinmaking
Regular Coder

 
Join Date: Oct 2011
Posts: 236
Thanks: 11
Thanked 5 Times in 5 Posts
devinmaking has a little shameless behaviour in the past
Quote:
Originally Posted by Cags View Post
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
devinmaking is offline   Reply With Quote
Old 10-06-2011, 11:16 PM   PM User | #4
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,604
Thanks: 2
Thanked 399 Times in 392 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Quote:
Originally Posted by devinmaking View Post
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
Inigoesdr is offline   Reply With Quote
Reply

Bookmarks

Tags
mod_rewrite

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:34 AM.


Advertisement
Log in to turn off these ads.