URL Syntax Question

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

By InHouse - September 22, 2009

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: [chris] URL Syntax Question

By InHouse - September 25, 2009

Worth a shot Chris, but unfortunately no joy.

Everything I'm reading tells me that something like this should work:
Options +FollowSymLinks
RewriteEngine on
RewriteRule event-details/(.*)/(.*)/(.*)/ event-details.php?prov=$1&cityName=$2&bizName=$3


I'm able to do simple redirects like adding a www. to domains that are missing it, so the .htaccess file is being read, but I just can't get this work. It's the last thing I need for this site and I really didn't expect this to be a big deal.

I'm assuming that there's no conflict being introduced though the use of CMBS, right?

I'm more than open to any suggestions from the forum users at this stage.

J.

Re: [Dave] URL Syntax Question - SOLVED

By InHouse - September 28, 2009

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.