View Full Version : Another URL rewrite issue

07-22-2011, 06:41 PM
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:

Options +FollowSymLinks
RewriteEngine On

RewriteRule . index.php

I'm getting a 500 error.

07-23-2011, 10:12 AM
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..

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

07-23-2011, 08:19 PM
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...

$page = explode('/',$_SERVER['PHP_SELF'])

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?

07-24-2011, 03:10 PM
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.

07-25-2011, 09:32 AM
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.

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

07-25-2011, 03:25 PM
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.