9 posts by 3 authors in: Forums > CMS Builder
Last Post: September 28, 2009   (RSS)

By InHouse - August 18, 2009

Hi there,

I'm trying to sort out a site which has multiple sub-sites based on city names. I'd like to use one page to display info for all cities, but configure the URL to display a city name as part of the path for good SEO.

i.e.:
Cities in Play: London, Vancouver, Edmonton...

Page:
cityinfo.php

URL: www.mydomain.com/London/cityinfo.php or
www.mydomain.com/Vancouver/cityinfo.php

I'd use the .htaccess file to also give us a redirect from:
http://vancouver.mydomain.com/ to
http://www.mydomain.com/Vancouver/cityinfo.php

The ideal would be for the cityinfo.php to recognize the path and pull the city name as a cue for loading the right city's data into the the page.

Questions:

1 - Can anyone suggest how to get CMSB to write these URLs automagically?

2 - Can anyone suggest an elegant way to pull the city name from the URL while allowing for possible further directories in the path?
i.e.:
we might have a path like:
www.mydomain.com/Vancouver/events/eventinfo.php

It might be reasonable to assume that the city name would always come after the .com/

Thanks in advance for any suggestions!

J.

Re: [InHouse] URL Syntax Question

By Dave - August 18, 2009

Hi Jayme,

For the custom urls, google for mod_rewrite.

We recently upgraded all our Instant Websites product pages to use CMS Builder. So even though they look like this:
http://www.interactivetools.com/products/instant-realty-website/
http://www.interactivetools.com/products/instant-auto-website/requirements.html
http://www.interactivetools.com/products/instant-listings-website/changelog.html
etc

They're actually all driven by PHP files. We a single .htaccess file in each of those folders that uses mod_rewrite to rewrite the urls and looks like this:

RewriteEngine on
RewriteRule ^$ /products/instant-website-viewers/index.php?num=1 [nc]
RewriteRule ^(.*)\.html$ /products/instant-website-viewers/$1.php?num=1 [nc]


So when you request:
http://www.interactivetools.com/products/instant-auto-website/requirements.html

What's requested behind the scenes is:
http://www.interactivetools.com/products/instant-website-viewers/requirements.php?num=2

So the first step is to get all the pages displaying the way you want without worrying about the urls. Then figure out how you want the urls to look. Then figure out the mod_rewrite rules to convert:

www.mydomain.com/Vancouver/cityinfo.php to /cityinfo.php?city=Vancouver
and vancouver.mydomain.com/ to /index.php?city=Vancouver

Hope that helps! Keep us up to date with your progress!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] URL Syntax Question

By InHouse - August 18, 2009

Thank you Dave. Food for thought as ever!

I wasn't really planning on having separate physical directories for each city. In a way, the URL showing a city name inline would be a fake. All the cities would display on the same physical page but the URLs would be masked as though they were in directories and not with the city=vancouver parameter hanging off the back. This may be what you're getting at and I just haven't absorbed it properly yet. It's getting late in the day in the eastern time zones. :-)

Ultimately, if I use mod_rewrite rules to mask the URLs, would the landing page still be able to pull the parameter after the equals sign, or would I have to parse the URL to look for the city name between the two /'s after .com/ ?

I may be mis-reading your instructions so I just want to be sure if I am or not.

J.

Re: [InHouse] URL Syntax Question

By Dave - August 18, 2009

No problem. It can take a little bit of experimenting, but you don't need separate directories, that's just how we did it. You could have one .htaccess file that makes the whole thing work.

Basically, with mod_rewrite you can take any incoming url and *rewrite* it before it hits the web server. And even if you add the ?city=vancouver on the rewritten url, no one would ever know or see that part. It would be as if they are in the directory.

It lets you separate the urls the user sees from the urls the web server sees.

A great way to experiment with this is if you have a local dev server setup (such as WAMPServer on windows).

But basically you can do everything you want to do, it will just take a bit of trial and error.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] URL Syntax Question

Sincere apology up front: this is off-topic and categorically not your problem, but after several hours of working this issue I'm stumped and would appreciate any input that the forum readers might offer.

Let's say you have a URL like:
http://www.domain.com/event-details.php?prov=ON&cityName=London&bizName=Wine,%20Women%20and%20Shopping-2

it would normally appear as:

http://www.domain.com/event-details.php?prov=ON&cityName=London&bizName=Wine, Women and Shopping-2


and you want it to appear as:
http://www.domain.com/event-details/ON/London/Wine, Women and Shopping-2

why would the following rewrite rule not work?
RewriteRule ^event-details/([^/]*)/([^/]*)/([^/]*)$ /event-details.php?prov=$1&cityName=$2&bizName=$3 [nc]

Any guesses would be welcome.
J.

Re: [InHouse] URL Syntax Question

By Chris - September 23, 2009

Hi InHouse,

Wild guess here: do you need to include the initial slash?

RewriteRule ^/?event-det...
All the best,
Chris

Re: [InHouse] URL Syntax Question

By Dave - September 28, 2009

Hi Jayme,

Here's some resources:

mod_rewrite tester:
http://civilolydnad.se/projects/rewriterule/

mod_rewrite cheat sheet:
http://www.addedbytes.com/apache/mod_rewrite-cheat-sheet/

debugging mod_rewrite:
http://www.latenightpc.com/blog/archives/2007/09/05/a-couple-ways-to-debug-mod_rewrite

Enable mod_rewrite logging:
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritelog

Basically add this to your httpd.conf (on a local dev server as it's resource intensive):
RewriteLog "/home/user/www/logs/rewrite.log"
RewriteLogLevel 9

If none of that helps send me an email with FTP details and I'll take a quick look for you and see if I can spot anything.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] URL Syntax Question - SOLVED

Thank you Dave. I do appreciate your comments.
I did find a few of these resources and tried dozens of variations until finally was pointed in the right direction. For those encountering similar issues, this is the syntax that finally worked:

RewriteRule ^event-details/([^/]+)/([^/]+)/([^/]+) /event-details.php?prov=$1&cityName=$2&bizName=$3 [NC]

Such small nuances but such a big difference.

Cheers,
J.