SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2012
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .htaccess Rewrite rule HELP!

    Hi ,
    I need to do a url rewrite such that files from the physical location parent/app/webroot/js/abc.js can be accessed by the url parent/js/abc.js
    What Should be my rule.
    Thanks in Advance
    Taz.

  2. #2
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by Fati Kom View Post
    Hi ,
    I need to do a url rewrite such that files from the physical location parent/app/webroot/js/abc.js can be accessed by the url parent/js/abc.js
    What Should be my rule.
    Thanks in Advance
    Taz.
    Hello,

    Please post mod-rewrite code that you have tried. We try not to do your work for you. It involves reading about mod-rewrite and serching on google for tutorials or reading over the documentation on apache.org.
    ictus==""

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2012
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ServerStorm View Post
    Hello,

    Please post mod-rewrite code that you have tried. We try not to do your work for you. It involves reading about mod-rewrite and serching on google for tutorials or reading over the documentation on apache.org.
    Hi,
    I am using these at the moment
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^$ webroot/ [L]
    RewriteRule (.*) webroot/$1 [L]

    </IfModule>

  4. #4
    SitePoint Enthusiast
    Join Date
    Sep 2012
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    rewrite module is already on, but it doesn't seem to work :S

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,656
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Steve,



    Fati,

    [standard rant #1]
    The use of "lazy regex," specifically the EVERYTHING atom, (.*), and its close relatives, is the NUMBER ONE coding error of newbies BECAUSE it is "greedy." Unless you provide an "exit" from your redirection, you will ALWAYS end up in a loop!
    [/standard rant #1]

    [standard rant #4]
    The definition of an idiot is someone who repeatedly does the same thing expecting a different result. Asking Apache to confirm the existence of ANY module with an <IfModule> ... </IfModule> wrapper is the same thing in the webmaster world. DON'T BE AN IDIOT! If you don't know whether a module is enabled, run the test ONCE then REMOVE the wrapper as it is EXTREMELY wasteful of Apache's resources (and should NEVER be allowed on a shared server).

    No, I'm not calling you an idiot, I'm saying not to abuse your server like this!
    [/standard rant #4]

    You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It's helped may members and should help you, too. One of the first things to learn about mod_rewrite is when NOT to use it. IMHO, you should change your DocumentRoot to webroot but, if that's not possible, use a Redirect statement as that's what it's designed to do.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  6. #6
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,281
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    @OP

    [standard rant #1 response]
    Within dklynn's explosive opinion is at least one good point: that (.*) needs to be used carefully. But beyond that bit of caution, don't be dissuaded. The use of (.*) is standard practice, and it's frequently used even in the Apache documentation itself. If you do read dklynn's tutorial, I strongly suggest you treat it as only a secondary supplement, and instead learn primarily from the official Apache documentation.
    [/standard rant #1 response]

    With that out of the way, back to your question.

    Based on your current htaccess and folder structure, I suspect you're using CakePHP. If that's the case, then you should already be getting your desired behavior, because CakePHP provides an htaccess for the "parent" folder that will already rewrite everything to app/webroot. If for some reason that htaccess is missing, then you can replace it with the copy I just linked to.
    "First make it work. Then make it better."

  7. #7
    SitePoint Enthusiast
    Join Date
    Sep 2012
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Regarding my Problem:
    @ Jeff Mott

    Thank you very much for your help , actually this was precisely what my problem was...I am using CakePHP and the htaccess in the parent folder was missing ....Thanks again.

    The discussion is getting very interesting and now I am a bit confused that when redirection is there to do the same job as url rewriting , why is it being used so widely , what are the advantages of using url rewriting over redirection ? what can we do with url- rewriting that we cannot do with redirection?
    can anyone provide me with that Insight?!!

    Thank you All for your comments...they are extremely valuable....

  8. #8
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,281
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Fati Kom View Post
    The discussion is getting very interesting and now I am a bit confused that when redirection is there to do the same job as url rewriting , why is it being used so widely , what are the advantages of using url rewriting over redirection ? what can we do with url- rewriting that we cannot do with redirection?
    can anyone provide me with that Insight?!!
    The difference can be thought of as external vs internal. Redirection means sending a 3xx status back to the browser with a new URL. Rewriting means you're changing how the server maps a URL path to a filesystem path. Redirection is useful if you want the outside world to be aware of the change, such as to let search engines know that a resource has moved. Rewriting is useful if you want the change to be transparent to the outside world, such as sending all requests to index.php.
    "First make it work. Then make it better."

  9. #9
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,656
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Fati Kom View Post
    The discussion is getting very interesting and now I am a bit confused that when redirection is there to do the same job as url rewriting , why is it being used so widely , what are the advantages of using url rewriting over redirection ? what can we do with url- rewriting that we cannot do with redirection?
    can anyone provide me with that Insight?!!
    There are a few differences:

    1. mod_alias is a core module, i.e., it is enabled by default and will always be run before mod_rewrite directives.
    2. mod_rewrite (RewriteRule et al) uses regular expressions while most of the mod_alias (Redirect) directives do not which translates directly to speed (mod_alias is faster).
    3. The POWER of regular expressions (especially when using RewriteCond statements to examine other variables) make it a more versatile tool.


    The first thing to learn before you use mod_rewrite, even before proper regex, is when to use it and when not to use it.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  10. #10
    SitePoint Enthusiast
    Join Date
    Sep 2012
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the comments everyone, I get it now.


Bookmarks

Posting Permissions

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