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 5 of 5
  1. #1
    Regular Coder
    Join Date
    May 2010
    Posts
    140
    Thanks
    7
    Thanked 0 Times in 0 Posts

    htaccess rewrite url

    I am using this code to rewrite the url if the file is in the main directory.

    Code:
    www.domain.com/file.php?a=1&b=2 [L]
    to www.domain.com/bar using
    Code:
    RewriteRule ^bar$ /file.php?a=1&b=2 [L]
    .

    How can I insert a subfolder?

    Code:
    www.domain.com/subfolder/file.php?a=1&b=2 [L]
    to www.domain.com/foo/bar

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    like
    Code:
    RewriteRule ^foo/bar$      /subfolder/file.php?a=1&b=2 [L]
    ?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    May 2010
    Posts
    140
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Ok, i finally got it to work by using this code

    Code:
    RewriteRule ^bar$ /foo/bar.php?a=1&b=1 [L]
    The key is to put this code in the foo folders .htaccess file.

    I thought that was the case but when I tested it, i must have missed a slash or something.

  • #4
    New Coder
    Join Date
    Jul 2011
    Posts
    67
    Thanks
    0
    Thanked 13 Times in 13 Posts
    If you wish to keep all your rules together, you should only have to append the subfolders name to the match.

    Code:
    RewriteRule ^foo/bar$ /foo/bar.php?a=1&b=1 [L]
    ... or even ...

    Code:
    RewriteRule ^(foo/bar)$ /$1.php?a=1&b=1 [L]

  • #5
    New to the CF scene
    Join Date
    Jul 2011
    Location
    Spain
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, I was looking for the same thing


  •  

    Posting Permissions

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