Welcome Guest, Not a member yet? Register   Sign In
How to rewrite URLS to remove index.php AND force lowercase?
#1

[eluser]jasonsack[/eluser]
I'm having trouble doing both of these at once with .htaccess.

Removing index.php is working, but trying to add the force lowercase keeps throwing a 500 error. Any help is appreciated!

here's my .htaccess code:

Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

RewriteMap  lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule "(.*) ${lc:$1} [R=301,L]
#2

[eluser]toopay[/eluser]
Why you need to force lowercase in your url?
#3

[eluser]jasonsack[/eluser]
For some reason if there are uppercase characters, it doesn't load the view and throws a 404 error.

However, I was able to fix the issue by adding this to the top of the base application index.php file:

Code:
$_SERVER['REQUEST_URI']=strtolower($_SERVER['REQUEST_URI']);

This doesn't rewrite or redirect the url, but it allows the controller to load the view with uppercase characters in the URL.

Am I better off doing this, or rewriting the url in .htaccess?
#4

[eluser]toopay[/eluser]
Your did the right thing. 'RewriteMap lc int:tolower' line in your htaccess configuration should be placed in 'httpd.conf' file in your server, which mean you may dont have access to do that thing.
#5

[eluser]toopay[/eluser]
But be carefull. You might be in trouble with other resource, which need uppercase character, such as images, javascript file, etc.

My suggestion is, don't modified somethings which already RIGHT. I mean, if user type the wrong character on browser addressbar, for example 'www.yoursite.com/FORUM', and they get 404 message, whats WRONG with this scenario??? User type WRONG address get error message, until user fix it, then he will get the RIGHT page.

If, you (try) anticipate this user's error by doing as you stated above, i think, that's WRONG.
#6

[eluser]jasonsack[/eluser]
Long story short, I have about 12 unique controller urls that are going to be given out to different users for them to enter manually. By chance that the user enters ‘www.yoursite.com/Forum’ instead of ‘www.yoursite.com/forum’ I don't want an error to return, i want it to load the view as if it were lowercase.

I am not worried about images, js or other files, as they are all controlled and named lowercase. No additional files will be added by the user.

Unless there is a way to allow the controller class to recognize uppercase characters in the controller URL? or rewrite the controller part of the URL with htaccess?

Thanks for the replies!
#7

[eluser]toopay[/eluser]
What browser you use right now?
#8

[eluser]jasonsack[/eluser]
Safari on a Mac. Browsers shouldn't matter though?
#9

[eluser]toopay[/eluser]
Try installing Chrome (or latest Opera), and test it on your Mac. yoursite.com/FORUM = yoursite.com/forum = yoursite.com/Forum = yoursite.com/fOrUm
#10

[eluser]jasonsack[/eluser]
Yeah, I've tried on different browsers, it's the same issue. Returns a 404 error.

Would it have something to do with the mod_rewrite code I have to remove the index.php from the URL?


here's just that code for reference:

Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]




Theme © iAndrew 2016 - Forum software by © MyBB