Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Oct 2011
    Posts
    237
    Thanks
    11
    Thanked 5 Times in 5 Posts

    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?

  • #2
    New Coder
    Join Date
    Jul 2011
    Posts
    67
    Thanks
    0
    Thanked 13 Times in 13 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Oct 2011
    Posts
    237
    Thanks
    11
    Thanked 5 Times in 5 Posts
    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

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    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


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •