Jump to content

Help with re-writing urls (mod_rewrite) in .htaccess


TOA

Recommended Posts

I've just inherited a site structure where the folders are capitalized (ex. www.site.com/Folder/page.php). It's my understanding that it's led to some user complaints about the url's being 'too picky'...ie. case sensitive.

 

Instead of going through an extensive amount of code line by line to change it, I thought I'd create a rewrite rule that maps any incoming lowercase urls to the first letter uppercase equivalent (only if it's between the //'s though -- a directory).

 

I've tried, but failed miserably to create the correct rule, and I've searched 'the engine that shall not be mentioned' but can only find examples of how to map to lowercase files/folders, not the other way around.

 

Can anyone offer some help to a frustrated soul?

Link to comment
Share on other sites

Just a thought:

 

Here's my current .htaccess (stripped of the site name for his protection)

 

Options +FollowSymLinks
RewriteEngine On  

# redirect .net, .org, etc to .com
RewriteCond %{HTTP_HOST} !^www\.site\.com
RewriteRule (.*) https://www.site.com/$1 [R=301,L]

# redirect to ssl
RewriteCond %{HTTPS} off  
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

# remove php extensions for friendly urls
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)$ $1.php

 

Would just adding the no-case flag to the first one work? Like this?

RewriteRule (.*) https://www.site.com/$1 [NC][R=301,L]

Link to comment
Share on other sites

I can answer that...nope it didn't. Tried

RewriteRule (.*) https://www.site.com/$1 [NC][R=301,L]

which caused an internal error and I tried

RewriteRule (.*) https://www.site.com/$1 [R=301,L,NC]

 

and that did nothing (that I could tell)

Link to comment
Share on other sites

Well, this is what I've come up with so far.

 

RewriteRule ^/[a-z]{1}.*(?=.) [A-Z]

 

I think the pattern is correct, but I'm not that good with them. I'm also not sure that last part is correct ([A-Z]). Will that turn the whole thing to uppercase?

 

Am I on the right track even? :confused:

 

Thanks for looking.

Link to comment
Share on other sites

Well, I didn't have any time over the weekend to try anything else, so I'm still looking for help with this if anyone's reading (although I'll probably have a few minutes this morning to try some things).

 

Thanks.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.