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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    htaccess within subdirectory help!

    hi there! I'm new here so hello all, looking for a little help with my .htaccess file.
    I'm not great with it but will try my best to explain.

    I'm using htaccess to rewrite my urls:

    http://www.domain.com/channel/1.php?id=$1 to
    http://www.domain.com/channel/1.html

    Now this used to work fine with the following in my htaccess:

    RewriteEngine On
    RewriteRule 1/(.*).html/ 1.php?id=$1
    RewriteRule 1/(.*).html 1.php?id=$1

    Sloppy I know and sorry for that but it worked.

    Anyway the problem I have now is that I've had a shift around with domain changes etc and now as a result the subdirectory along with the .htaccess file is buried a folder further back

    Since then I can't get the above rewrites to work and I think the reason is because of the change with folders within my server.
    Any advice or help would be much appreciated.
    If it makes a difference I use godaddy shared hosting

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    If you've changed structure, you may need to change the rewrite rules. The pattern itself can remain unchanged, but the sub-directories may need to change.
    By default rewrite will search your pattern above to find a subdirectory from this .htaccess' directory called 1/.*html, and map it back to a file called 1.php within this directory. If you need to move to the parent, start using / in your replacement where / represents your directory root.
    So if you want to match site.com/sub/1/id.html to site.com/1.php?id=id, then you would need to use:
    Code:
    RewriteRule 1/(.*)\.html/? /1.php?id=$1
    And place this .htaccess in /sub. If you want to fetch a .php buried within a sub-directory, you must target it as being in a sub-directory. You can also use rewrite conditions to determine where you are first, and match only based on those rules.
    So yes the structure of the filesystem is very important in both your matching and your mapping rules. Changes to it will require rewriting the rewrite rule to properly match and replace.

    This also hasn't a thing to do with PHP, moving to Apache Configurations forum.


  •  

    Posting Permissions

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