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 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts

    need htaccess help!

    Hello,

    I don't know much about htaccess, but i'm trying to redirect all stuff coming from index.php to the root, so e.g. /index.php?test=1 becomes /1, now that WOKRS. But now here's my problem, i cannot make any new php files because if i would go to /anotherfile.php it would redirect to the root again...

    Here's the code:

    Code:
    RewriteEngine On
    RewriteRule (.*) index.php
    Can anyone help so i can add new php files that won't be redirected?

  • #2
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    Try the following

    Code:
    RewriteEngine on
    RewriteBase /
    RewriteRule ^(.+)/?$ /index.php?page=$1 [L]
    now, when you create links in your html, make sure it starts with "/"...for example
    <a href="/about/">about</a>
    <a href="/contact/">contact</a>

    Let's know if that didn't work

    cheers,
    Ess

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ess View Post
    Try the following

    Code:
    RewriteEngine on
    RewriteBase /
    RewriteRule ^(.+)/?$ /index.php?page=$1 [L]
    now, when you create links in your html, make sure it starts with "/"...for example
    <a href="/about/">about</a>
    <a href="/contact/">contact</a>

    Let's know if that didn't work

    cheers,
    Ess
    Well i tried it, but it gives me a 404...

  • #4
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    is mod_rewrite enabled?

    you wish to have a look at the following url, they seem to provide a interesting solution

    http://framework.zend.com/wiki/displ...r+URL+Rewriter

    cheers,
    Ess

  • Users who have thanked ess for this post:

    koolaid (09-02-2007)

  • #5
    New Coder
    Join Date
    Aug 2007
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ess View Post
    is mod_rewrite enabled?

    you wish to have a look at the following url, they seem to provide a interesting solution

    http://framework.zend.com/wiki/displ...r+URL+Rewriter

    cheers,
    Ess
    Messed around a bit, and it works! Thanks a million! Small question though, what does the '^' in front of '(.+)' mean?
    Last edited by koolaid; 09-02-2007 at 07:30 PM.

  • #6
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    ^ means match the beginning of a given value

    for example
    ^([a-z]+)(\s)([0-9]+)$

    the above expression states the string must start with at the least one letter, which could be a, b, c....all the way to z

    $ means the ends of a string
    in the above example, a value would evaluate to true if it ends with at the least one number 0-9

    for more info, please check the following url
    http://www.regular-expressions.info/

    cheers,
    Ess


  •  

    Posting Permissions

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