1,105,594 Community Members

using mod_rewrite

Member Avatar
codemonkey88
Light Poster
27 posts since Mar 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
vibhaJ
Posting Shark
960 posts since Apr 2010
Reputation Points: 126 [?]
Q&As Helped to Solve: 190 [?]
Skill Endorsements: 3 [?]
 
1
 

Try this.

RewriteEngine On                          
RewriteRule ^([^/]+)$ /index.php?url=$1 [L]
RewriteRule ^/article/([^/]+)$ /index.php?url=$1&type=news [L]
Member Avatar
codemonkey88
Light Poster
27 posts since Mar 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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...

Member Avatar
codemonkey88
Light Poster
27 posts since Mar 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
vibhaJ
Posting Shark
960 posts since Apr 2010
Reputation Points: 126 [?]
Q&As Helped to Solve: 190 [?]
Skill Endorsements: 3 [?]
 
1
 
Member Avatar
codemonkey88
Light Poster
27 posts since Mar 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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:)

Question Answered as of 2 Years Ago by vibhaJ
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: