views:

24

answers:

1

This is a totally new area for me so please be patient. I want to create "permalinks" for a dynamic site I am working on. At the moment all the pages (not the index) are referenced using an ID variable thus:

http://www.domainname.com/page.php?ID=122 (etc)

I want to create a suitable rewrite rule so that a useable URL would be more like this:

http://www.domainname.com/page/'pagetitle'.html (could be .php doen't matter)

Page title is stored in the database and obviously is linked directly to the ID

Am I right in thinking thr rewrite rule would be something like this?

RewriteCond %{QUERY_STRING} ^(([^&]*&)*)ID=([^&]+)(&+(.*))?$

RewriteRule ^page\.php$ /page/%3?%1%5 [L,R=301]

My ideal would be to just create

http://www.domainname.com/'pagetitle'.html

But have absolutly no idea how to do that.

Now the other question/sub question.

If the rewrite works i.e. you type in http://www.domainname.com/page/'pagetitle'.html to a browser address bar does the htaccess file work "the other way" in accessing the page http://www.domainname.com/page.php?ID=122 or do I have to create a function to take the 'pagetitle'.html bit of the URL and convert it to page.php?ID=122 ?

Also, sorry, but this is all new; if I create a site map (xml or php etc) using http://www.domainname.com/page/'pagetitle'.html will the SE spiders go to http://www.domainname.com/page.php?ID=122? or di I need to create the sitemap using the ID variables?

A: 

Question 1 and 2: The condition is not required in this case. Use it like this:

RewriteRule ^/page/([\w-]+).html$ /page.php?title=$1 [L,R=301]

This transforms /page/blabla.html to /page.php?title=blabla You need to find the right page using the title parameter in page.php

Question 3: I suggest you never use the querystring variant of the urls in any of your anchor links or xml sitemap. This way the spiders will only know of the friendly urls.

Fabian
Hi fabian thanks for that, simple question looking at your Rewrite rule - would RewriteRule ^/([\w-]+).html$ /page.php?title=$1 [L,R=301] work? i.e. take out page/
RussP
Yes it would. This would rewrite /blabla.html to /page.php?title=blabla.
Fabian
Oh and [\w-]+ simply means any letter or digit and the hyphen with 1 or more repetitions. You should change this to suit your needs.
Fabian
Thanks Fabian, help much apprecaited
RussP