Forum Moderators: phranque
RewriteEngine on
RewriteRule ^([a-z0-9])\.html$ /parse.php?data=$1 [NC,L]
This allows me to enter 'foobar.html' which calls 'parse.php?data=foobar'. This is ALMOST what I want. I need to do something like:
'joemama-was-here-today.html' and have it parse out the first set of characters up to the 1st '-', resulting in a similar call to 'parse.php?data=joemama'.
Is this possible? Thanks.
maybe something like this?
RewriteRule ^([^-]*)[-a-z0-9]*\.html$ /parse.php?data=$1 [NC,L]
The correct way to do this, is for the remaining words to be checked against the database and all except the 'one' correct version should result in a 404 error being returned.
So that leaves me needing another RewriteRule which hopefully you or Phranque could help me with. I would also like to make sure that the script is only called when there is a combination of 5 alphanumeric characters followed by a hyphen at the beginning of the string. For example:
00001-blue-skies-bring-tears.html would call /parse.php?id=00001&title=blue-skies-bring-tears
Thanks for all the help guys.
([0-9]{5})-(... instead. It matches five digits and a hyphen.
It doesn't match if any letters are present before the first hyphen, or if there are more or less than five digits.
If you really do need five letters and numbers then this would do it:
([a-z0-9]{5})-(... assuming the letters are always lower case. Your script would need to generate the 301 response, using two HEADER commands (one to say "301" and the other for the new URL).
Again, your backend script would need to verify the name against the data base and redirect to the correct URL when an incorrectly cased request is received.
That is, the real document ID is 6e4ad but NC would "make" 6e4Ad and 6e4aD and several other combinations also appear to be "valid".
You need to avoid that Duplicate Content scenario by making only one form able to return "200 OK", and all the others return 301 or 404. That's down to your script.