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?

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]

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)

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.

Archived

This topic is now archived and is closed to further replies.

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