Wednesday, April 4, 2012

Redirect of URL using PHP

I set our new server up like this

studentau.edutech.org/moodle.

I have already omitted /moodle more than once while browsing to the server. I probably should have done the install of the moodle core files directly into the www directory, but I remember choosing to keep them in the moodle folder, hence the /moodle on the URL.

If someone tries to browse to studentau.edutech.org, and forgets the /moodle part, it fails with a message. That's a no go.

I need to catch the URL that is lacking the /moodle and add it, or redirect the URL to with the /moodle included.

I should probably use Apache, but for now, I am using this simple solution.
  • Create a copy of this file www\index.php
  • Rename copyofindex.php to windex.php
  • Gut index.php, replacing its content with this simple php command:
  • header("Location: http://studentau.edutech.org/moodle");
Now anyone omitting the /moodle in the URL and accidentally lands at studentau.edutech.org is gently redirected to the proper URL, none the wiser.

If I want to access the WAMP home page, I browse to www\windex.php - no harm no foul.

Moral of the story?

Sometimes the simpler solution is best, at least for now.

I also put our *old moodle 2.0. instance in maintenance mode with a message indicating the site has been deprecated, with a link to the new site. I do not want any of my customers to be confused about which server or moodle are we using.

No comments:

Post a Comment