Does anyone know about cleaning up URLs for CMS?

I had a .htaccess file containing the following code (or so far as I can remember)

RewriteEngine On                          
RewriteRule ^([a-z])$ /index.php?url=$1 [L]
RewriteRule ^/article/([a-z])$ /index.php?url=$1&type=news [L]

which was working fine ie: www.mysite.com/somepage loaded the "mypage" content into my index.php file (www.mysite.com/index.php?url=mypage)

However, when adding content, I came across a situation where the url was containing both numbers and letters, which of course won't work with this pattern. I changed the [a-z] bit to a wildcard, which returned a 500 error, so I changed it back again and just get a 404 error.

I have been through all the forums and what feels like hundreds of different rewrites, but they all return 404 errors - even redirecting everything to the index.php file :S

Any ideas where I could be going wrong? It's so infuriating that it was working in what I think was the same code!!!

By the way, I have also tried altering whitespace as I know this can cause a problem in some languages.

Try this.

RewriteEngine On                          
RewriteRule ^([^/]+)$ /index.php?url=$1 [L]
RewriteRule ^/article/([^/]+)$ /index.php?url=$1&type=news [L]

Thanks for the reply, but that doesn't seam to work either :(

Its hosted at http://excellency.x-brand.co.uk if anyone wants to look.

I was searching the forums again and came accross a suggesstion to put random characters in the .htaccess file to see if it actualy loads, which I tried but the error log displays "unauthorised command" which implies everything should work.

Not sure if I can test if modrewrite is in the conf file as I don't have one on my shared hosting, but if I have used it before, I see no reason why it would suddenly turn off.

I think I'll go and find a wall...

note to self: don't overwrite files until you have tested the new version!

ok, oddly enough the test doesn't work either - I guess they must have done something on the server. I've come up with a bit of a workaround - if a little clumsy:

To the htaccess file I have added the line

ErrorDocument 404 /index.php

I can then use REQUEST_URI within the index.php file - which by the way, has its own 404 page anyway for where the url doesn't match an SQL result.

Thanks for your suggesstions:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.