Forum Moderators: phranque

Message Too Old, No Replies

How to redirect & serve virtual web pages

         

Jenn8

3:36 am on Nov 5, 2015 (gmt 0)

10+ Year Member



I have searched google and this site for hours, looking for an easy to follow ( I need the Mr Men version :) ) of how to achieve this. Some sites, particularly social media sites, dating sites and similar have urls such as http://www.example.com/member-name/ ; clearly the directory /member-name/ does not exist, in the case of FaceBook that would entail millions of directories on their servers! So obviously http://www.example.com/member-name/ redirects to something like http://www.example.com/somephpcontent/servepage.php where the "member-name" is found in a database and the content served dynamically accordingly from the database. If the url was http://www.example.com/content/index.php?member-name, that I know how to do, but how to get to that equivalent point is baffling me. I have limited control over my shared hosting server which runs apache, mysql, php 5.5 on centos with cpanel. My hosting package does allow me to use .htaccess. I need to know how not only to redirect a large quantity of http://www.example.com/a-members-name/ to the one real directory and page, but also make available to the serving page as a variable the /a-members-name/ part of the url.

I would be very grateful is one of you gurus could explain to this simple rather dumb soul in words of one syllable how this can be achieved and how it works, I also have problems getting my head around regex expressions so please be gentle with me :)

lucy24

4:50 am on Nov 5, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I need to know how not only to redirect

Nope. You need to know how to rewrite. So that's your first lesson :)

redirect (external) = send a message back to the visitor (for example, a human's browser) instructing them to make a fresh request at some other URL.
rewrite (internal) = allow the visitor to think they're at the originally requested URL, while secretly serving content from some completely different place. Well, not completely different: on shared hosting it has to be on the same domain.

The basic pattern looks like this:

RewriteRule ^(blahblah)/$ /somewhere-else.php?name=$1 [L]

located after any existing external redirects in the mod_rewrite section of your htaccess.

But of course it's never quite that simple. For starters: If you have any existing redirects using mod_alias (Redirect by that name) you'll need to change them to use mod_rewrite syntax. (This is easy and can be done globally.) And then you've presumably got real, physical pages whose URL is also example.com/blahblah/ so you'll need a RewriteCond making exceptions. Also, you'll need to redirect (not rewrite!) requests in the form
example.com/membername
and
example.com/membername/index.html
because search engines will ask for these two forms, and since they're not real directories, mod_dir won't do it for you.

That will do for starters. Something tells me you will end up understanding exactly how to do it and it will work out fine; we just need to work through it step by step.

Jenn8

5:30 am on Nov 5, 2015 (gmt 0)

10+ Year Member



Thanks Lucy, I am going to do a crash course in mod_rewrite and test what I find out despite my regex dyslexia, will let U know how I get on, but I am sure I will have more questions than answers :)