SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Mar 2004
    Location
    USA
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mod_rewrite and .htaccess file locations

    Hi there. I was just curious about the .htaccess file location. I am just currently playing around with mod_rewrite. And I think I might have found the source of my problem. Here's the full "test" scenario I am trying to work out.

    I have created a test folder from my domain, in the effect of http://www.good411.com/url_rewrite/. Currently it gives a 403 error. However if you go to http://www.good411.com/url_rewrite/index.htm you will see my web page I am playing with. I currently have an .htaccess file in the /url_rewrite/ folder.

    The contents of /url_rewrite/.htaccess is:
    PHP Code:
    Options +FollowSymLinks
    RewriteEngine On
    Rewritebase 
    /url_rewrite
    RewriteRule 
    /url_rewarite/(.*) /echo.php?what=$1
    RewriteEngine Off 
    So is the problem that I need to move that .htaccess file to the root? Or what kind of suggestions can you give me?

    Btw the code of /url_rewrite/index.htm is:
    PHP Code:
    <A href="echo.php?what=hello" target="_blank">Hello</A><br/>
    <
    A href="echo.php?what=goodbye" target="_blank">Goodbe</A><br/>
    <
    A href="echo.php?what=whatever" target="_blank">Whatever</A><br/> 
    And the code of /url_rewrite/echo.php is:
    PHP Code:
    <? echo $what?>
    Thanks,
    Sean W.

  2. #2
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Sean,

    the content of /url_rewrite/.htaccess may be:

    /url_rewrite/.htaccess
    Code:
    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^([^.]*)$ echo.php?what=$1 [L]
    ([^.]*)
    means:
    A string of characters except the dot, the string can be empty.

    Asking for:
    example.com/url_rewrite/
    what should contain empty

    Asking for:
    example.com/url_rewrite/pippo/
    what should contain pippo/

    I never used RewriteBase, but I don't think you need it.


    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03

  3. #3
    SitePoint Member
    Join Date
    Mar 2004
    Location
    USA
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool..

    Ok see I was under the wrong impression about this mod_rewrite thing.

    as you saw above the code in my index.php file was:
    PHP Code:
    <A href="echo.php?what=hello" target="_blank">Hello</A><br/> 
    <
    A href="echo.php?what=goodbye" target="_blank">Goodbe</A><br/> 
    <
    A href="echo.php?what=whatever" target="_blank">Whatever</A><br/> 
    I thought that by doing that, the URL's written on the page would be automatically changed from echo.php?what=hello to /echo/hello

    That is not the case, after I changed my mod file to what you specified I could
    type: http://www.good411.com/rwtest/hello and I get the affect I wanted of just a simple echo of hello. So I guess I wanted mod_rewrite to have more magic in it than it really did.

    Thanks everyone.

    A leason well learned. mod_rewrite just interprets the inbound URL, does not change the links on the page.

    Thanks,
    Sean W.


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
  •