2

I am attempting to redirect & rewrite some dynamic PHP URL's to pretty and SEO friendly URLs. I have manged to do this successfully through .htaccess with the following code:

RewriteCond %{QUERY_STRING} ^somevar=green&nodescription=([a-zA-Z0-9_-]*)$
RewriteRule (.*) /green\/%1\/? [L,R=301]

RewriteRule ^green/([^/]*)/$ /script.php?somevar=green&nodescription=$1&rewrite=on [L]

This creates a somewhat pretty URL as follows:

 http://www.mysite.com/green/aA43-/

As I say, this works absolutley fine. Apart from one thing. The parameter nodescription contains a non-descriptive random set of letters, numbers and other characters.

I would like to rewrite the nodescription parameter to a more descriptive one. I understand that I can do this with a rewritemap through Apache. However, I have no experience at doing soemthing like this, and I'm not entirely sure where to start.

Normally I would simply alter script.php so that it contains more descriptive parameters, but this time I have no control over the script; I am pulling it from another site using cURL.

Can anybody give me an example of how to pull this off?

Thanks!

Matt

Matt
  • 345
  • 1
  • 6
  • 16
  • Further research suggests access to the apache httpd.conf config file is required in order turn on the rewritemap function. Unfortunately I don't have access to this file (shared hosting). So, I am still seeking a solution to this problem.. Any help gratefully received :) – Matt May 04 '11 at 22:58

2 Answers2

1

Well, to answer my own question, to pull this off you need access httpd.conf file on your apache server. My shared hosting company didn't allow access to this file (I doubt any would allow you access).

So I bit the bullet and purchased a VPS. I will post the steps I took here in order to set the rewritemap up in the hope that it will help a lost soul :) Ok, here goes...

My VPS has WHM installed, so in WHM I went to:

Server Configuration >> Apache Configuration >> Include Editor

Pre Virtual Host Include >> All Versions

This feature takes any text you put in and includes it in your httpd.conf file without worrying that it will be overwritten at a later stage. If you don't have WHM on your server then you can add the text directly to your httpd.conf file; make sure it is outside and before any virtual hosts.

OK, so I included the following map declaration and rewrite rule:

#Map to redirect (swaps key and value)
RewriteMap rwmap txt:/home/*/public_html/rdmap.txt

<Directory /home/*/public_html/test>

Options All -Indexes
RewriteEngine on

RewriteRule ^url/([^/]*)/$ /script.php?foo=${rwmap:$1|$1}&rewrite=on [L]

</Directory>

The actual map is a simple text file containing key/value pairs - you need to place this file in the directory declared in RewriteMap rwmap txt:/home/*/public_html/rdmap.txt.

And there you go. Apache now rewrites my URLs for me and I now have some nice and pretty SEO optimized links thanks to my rewrite map! Hoorah!

Matt
  • 345
  • 1
  • 6
  • 16
  • Thanks! I am in the same situation. My host does not allow RewriteMap so I am gonna have to go with a VPS! This will be useful :) – Drew Aug 23 '11 at 00:39
0
RewriteEngine on
RewriteRule ^green/([^/]*)/(.*)$ /script.php?somevar=green&nodescription=$1&rewrite=on [L]

This rewrite will allow you to pass "arbitrary text" that has nothing to do with the rewrite. For example:

http://www.mysite.com/green/aA43-/some-seo-boosting-title

Will still reroute correctly to script.php; the latter part will simply be ignored by the rewrite.

jlee
  • 492
  • 5
  • 15
  • Thanks for your answer. This is actually a nice and simple solution and was staring me in the face but I didn't see it. The problem is I want to get rid of the `/aA43-/` part of the URL completely, substituting it with /`some-seo-boosting-title`. I don't think your solution would achieve this? – Matt May 04 '11 at 16:29