Jump to content

Need help capturing first word after domain name in CMS


Recommended Posts

I have a series of websites with World sections that display pages at URL's like...

 

www.MySite.com/World

www.MySite.com/World/Mexico

www.MySite.com/World/Hawaii

 

...where Mexico and Hawaii are values stored in a database table. However, one site is different in that the site's home page is also the home page for the World section (and other sections). It displays URL's like this:

 

www.MySite.com (equivalent to www.MySite.com/World above)

www.MySite.com/Mexico

www.MySite.com/Hawaii

 

There are some conflicts between my home page and section home pages (e.g. MySite/Topics/index.htm) in my .htaccess file. If I make it work online, then it doesn't work on my local sites. So I want to try making it work with just ONE static page on the entire site: MySite.com/index.php.

 

Below is an example of the code I use to allow pages from the World section to display:

 

$result = mysql_result(mysql_query("SELECT COUNT(URL)
FROM gw_geog_urls
WHERE URL = '$MyURL2'"),0);

switch ($result)
{
case 1:
break;
case 0:
include_once(404.php");
break;
default:
include_once(Dupe.php");
break;
"

 

I'd like to modify my script so that pages from other sections will also display. Let's use the Topics section as an example. I'd like to find a script using PHP and/or REGEX that says...

 

if the $result is 0, display a 404 error page, UNLESS the domain name is followed by the word Topics. ANY of the following would qualify:

 

MySite/Topics

MySite/Topics/

MySite/Topics/Food

MySite/Topics/Food/Grains

MySite/Topics/xYz

 

If the URL is any of the above, that will trigger an include that will handle the Topics section, which will allow the first four URL's and display a 404 error page in place of MySite/Topics/xYZ.

 

This would NOT qualify, because the word Topics doesn't follow the domain name:

 

MySite/Arizona/Topics

 

It might still be displayed, but it's already taken care of with some additional code I've written.

 

I would also like to assign the value $MySection = Topics to any and every URL in which Topics follows the domain name.

 

Using another example, let's consider the Reference section.

 

MySite/Reference

MySite/Reference/

MySite/Reference/Horses

MySite/Reference/Typo

MySite/References/

 

The first four pages should have the value $MySection = Reference. The fifth one doesn't match, because it says ReferenceS (with an s at the end).

 

The first four URL's will fetch an include which will weed out the fourth URL (404 error page) but display regular pages for the first three.

 

Sorry for the long explanation, but I wanted to make sure I explained it clearly.

 

Thanks for any tips!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.