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
    Jan 2008
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Another URL rewrite issue

    I'm not sure if I need mod_rewrite. I've read lots of tutorials but I can't get my head around this.

    I have my home page, www.domain.com
    I have my scripts folder, www.domain.com/scripts

    I have my index.php, in the base directory which detects the URL.

    Therefore, I want EVERY SINGLE URL to redirect run index.php

    Let's say the URL is www.domain.com/signup/validate/hGjsopfE

    This would process in index.php, and within that PHP script will check the first piece of the URL (signup) and include, say, register.php [this is just to show that the URL does not necessarily mean the actual script name].

    At the moment I have only got the following in my .htaccess file:

    Code:
    Options +FollowSymLinks
    RewriteEngine On
    
    RewriteRule . index.php
    I'm getting a 500 error.

  • #2
    New Coder
    Join Date
    Jul 2011
    Posts
    67
    Thanks
    0
    Thanked 13 Times in 13 Posts
    That's because the . pattern you are matching with also matches index.php so you end up in an infinite loop. You need to tell it to not redirect on that page. A common solution is..

    Code:
    RewriteCond %{REQUEST_URI} !index.php
    RewriteRule . index.php

  • #3
    New Coder
    Join Date
    Jan 2008
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK so it still hasn't worked but thank you for your reply.

    You've fixed the problem but perhaps my method is still flawed!

    http://www.domain.com/hefkjwafk will load index.php, but doing a print_r() of the URL array gives...

    Code:
    $page = explode('/',$_SERVER['PHP_SELF'])
    print_r($page);
    
    gives... 
    Array ( [0] => [1] => index.php )
    So then how do I take the actual URL that we want?

    Also I've just realised... this will mean that all images, stylesheets etc will also run through index.php - how can I prevent this?
    Last edited by nxzmplty; 07-23-2011 at 07:31 PM.

  • #4
    New Coder
    Join Date
    Jan 2008
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wow, OK, I think this has been a stupid exercise and a complete waste of time.

    When I do phpinfo() there is NO instance of which apache modules are actually installed - does this mean that they are not installed, or that phpinfo() has been configured to not show this?

    My host is one.com - they seemed good enough on first impression, but they have told me that they can not add more apache modules.

    So I guess I have to find a new host - as my code works perfectly on xampp.

  • #5
    New Coder
    Join Date
    Jul 2011
    Posts
    67
    Thanks
    0
    Thanked 13 Times in 13 Posts
    If you successfully did a re-directed and didn't get a 500 server error then mod_rewrite is definitely installed, and if you can use PHP code then you definitely have that installed. That said you shouldn't need to switch hosts. If you wish to process the original URL then you simply need to pass it on along with the redirect.

    Code:
    RewriteCond %{REQUEST_URI} !index.php
    RewriteRule ^(.+)$ index.php?url=$1

  • #6
    New Coder
    Join Date
    Jan 2008
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the reply I can't wait to get home and try. I actually already changed host while keeping one.com as my registrar. For 9 quid I figured I'd keep them for a bit of emergency data.

    I was getting lots of 500s for all kinds of htaccess issues, and actually they've told me to remove the options symlinks bit to make it work.

    Gone back to my usual, reliable and worth-the-extra-money host.

    Cheers.


  •  

    Posting Permissions

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