Forum Moderators: phranque

Message Too Old, No Replies

What am I doing wrong?

         

jayer

11:05 pm on Nov 29, 2008 (gmt 0)

10+ Year Member



RewriteRule ^([A-Za-z]+)/index\.htm$ /General/index.php?school=$1

I'm trying to show

http://www.example.com/General/index.php?Akron

at

http://www.example.com/Akron/index.htm

Thanks in advance!

[edited by: tedster at 4:15 am (utc) on Nov. 30, 2008]
[edit reason] no specific urls, please - use example.com [/edit]

g1smd

12:27 am on Nov 30, 2008 (gmt 0)

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



You don't say in what way it fails.

However note that your example code has

/General/index.ph[b]p?school=[/b]$1
in it, but your example server filepath has only
/General/index.ph[b]p?[/b]Akron
in it.

In order for the code to work, the links on your page need to use the new (without parameters) format.

Mod_Rewrite does not alter URLs. It takes an incoming URL request and uses the rule to fetch the content from a place on the server that is different to the place that the URL might have suggested that it is located at. The request is generated by clicking a link on a page. That page has to show the URL that you want the user to see.

In general it is a bad idea to include index.html in a URL. The canonical form is without that included.

I would go further and go extensionless as well as ensuring the URL is entirely in lower-case.

e.g. www.example.com/akron

You need to ensure that requests for robots.txt, images, stylesheet and JS files, SE verification files, and so on are *not* captured by the rewrite.

Ahead of your rewrite you need a non-www to www 301 redirect so that your site doesn't serve content at both URLs.

Additionally, direct requests for the old URL should ideally redirect to the new URL so that the old URL does not get indexed by search engines.

phranque

12:37 am on Nov 30, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], jayer!

your RewriteRule includes a school= parameter and your example url doesn't, so there's an apparent inconsistency there.

jayer

12:48 am on Nov 30, 2008 (gmt 0)

10+ Year Member



That was just a mistype on my part.

http://www.example.com/General/index.php?school=Akron

That is what I was trying to pull from. I got it to work for just http://www.example.com/Akron/, but I still can't get it to work for http://www.example.com/Akron/index.htm.

[edited by: tedster at 4:16 am (utc) on Nov. 30, 2008]

g1smd

1:09 am on Nov 30, 2008 (gmt 0)

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



To add to what I wrote above, you also need to add [L] to the end of the rule.

jdMorgan

6:54 pm on Nov 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To serve "/General/index.php?school=$1" in response to requests for both
"/xyz/index.htm" and "/xyz/", make the "index.htm" part of the pattern optional:

RewriteRule ^([A-Za-z]+)/(index\.htm)?$ /General/index.php?school=$1 [L]

However, be aware that this introduces a duplicate-content problem, and you should really pick either "/xyx/" or "/xyz/index.htm" as the canonical URL, link to only that canonical URL on all pages within your site, and 301-redirect the non-canonical variant to the canonical URL.

Jim

jayer

7:17 pm on Nov 30, 2008 (gmt 0)

10+ Year Member



What's the big deal if there is duplicate content?

g1smd

7:51 pm on Nov 30, 2008 (gmt 0)

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



Your PageRank ends up split across multiple URLs.

Google gets to choose which URL to list - often not the one you wanted.

It screws up your Analytics.

It can harm your site. Check the list of sticky threads at the top of the Google forum.