htaccess Redirect Subfolder only (to lower case) - .htaccess

I've been searching and there are so many different examples here, but can't seem to find exactly what I need. Shared Environ...no access to httpd.conf
www.mysite.com/SuBfolder1/FiLe1.php (camel case)
www.mysite.com/SUBFOLDER2/FILE2.php (all caps)
www.mysite.com/subfoldeR3/filE3.php (one cap)
... and so on with many different subfolders...
In any of these instances...I'd want to redirect to the lowercase version of 'subfolderx'. But not affect anything below those folders. Some files under these folders may have caps too so I don't want the entire URL converted to lowercase.
Desired outcome:
www.mysite.com/subfolder1/FiLe1.php
www.mysite.com/subfolder2/FILE2.php
www.mysite.com/subfolder3/filE3.php
and so on for any subfolder
I think I could do something like this, but trying to do dynamic.
RewriteCond %{REQUEST_URI} ^/SuBfolder1
RewriteRule (.*) /subfolder1/ [R=301,L]

Related

How to convert ULR not existent subfolder to GET variable in .htaccess?

Need to convert subfolder named exact length of chars to GET variable. If posible, code that will work and on any other than 127.0.0.1 address.
Perfect will be that logic - if in request is some subfolder named with three chars(letters or numbers), and this folder is before last slash(/) - just convert this subfolder to GET variable, maintain any other GET variables if was there.
Need to convert path from this:
http://127.0.0.1/truck/c4/sD2/
To this:
http://127.0.0.1/truck/c4/?r=sD2
Or this:
http://127.0.0.1/truck/c4/index.php?r=sD2
Very important, "sD2" - is just random code for internal purposes. It generated randomly, so it not be like that always. But it always has three chars and slash(/), so somehow need to identify htose three chars and rewrite URL to transfer it with GET variable.
Also it should keep any other GET variables in current URL if has so.
Also need to .htaccess file to be on /truck/c4/ folder, and with possibiliy to move this root folrer to another domain.
For now i have this .htaccess code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} /?([/]..[^/])/$
RewriteRule /?(...)/$ http://127.0.0.1/truck/c4/?r=$1 [R=301,L,QSA]
</IfModule>
It works, but i very need to untied code from specific address to make it more universal, if possible.

URL redirect to use subdirectory as GET parameter

I imagine this has to be a common scenario but I'm struggling to describe it sufficiently well or to find a working answer!
Essentially I want to make hundreds of URLS that include unique reference codes but that are easy to type in the form example.com/aabbcc, which will be intercepted and all delivered to a PHP script for validating that code, located somewhere like example.com/script.php.
I need the subdirectory part of the URL (aabbcc, in this example) to become a GET parameter for that script, so a URL like the one above would be sent to example.com/script.php?id=aabbcc, while hiding this more complicated URL from the user.
I can see from other .htaccess examples that this must be possible, but I can't find one doing this.
Is there a .htaccess solution for it? Is there something else even more basic? Your help is appreciated in steering me.
If your "unique reference codes" consist of 6 lowercase letters, as in your example then you can do something like the following in your root .htaccess file using mod_rewrite:
RewriteEngine
# Internally rewrite "/abcdef" to "script.php?id=abcdef"
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^[a-z]{6}$ script.php?id=$0 [L]
If you don't need direct access to any subdirectories off the root that also happen to match a "unique reference code" then you can remove the preceding condition (RewriteCond directive). With the condition in place then you naturally can't access any "unique access codes" that happen to also match the name of a subdirectory.
$0 is a backreference to the entire URL-path that the RewriteRule pattern (first argument) matches against.
Reference
Apache mod-rewrite Documentation - Contents
Apache mod_rewrite Introduction
Apache mod_rewrite Reference
RewriteRule Directive
RewriteCond Directive

olddomain.com(path and file(s).pdf) to newdomain.com (path and file(s).pdf)

olddomain.com/path/file(s).pdf contains several hundred files that are pdfs with unique names.
We have a newdomain.com and the path is the same and the files are the same except when a user types in olddomain.com/path/file.pdf we want them to automatically be sent to newdomain.com/path/file.pdf
Again, the file names and the paths are identical, just want a way to redirect the domain names portion.
Try this rule.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.pdf -f
RewriteRule ^path/(.*) http://www.newdomain.com/path/$1.pdf [R]

Ho do I write an .htaccess redirect for a directory containing an ellipsis

Some how I had an invalid directory indexed in Google, and because of some dynamic relative links I now have 2500 "missing" pages indexed. I'm trying to use an .htaccess 301 redirect to correct the problem but I can't seem to get it to work. I need to redirect www.domain.com/shop/pc/.../pc/filename.asp to www.domain.com/shop/pc/filename.asp.
The rule I have written that doesn't want to work is RewriteRule ^shop/pc/\.\.\./pc/(.*)$ /shop/pc/$1 [R=301,L]
Any thoughts?
mod_rewite uses PCRE, so for these Unicode characters (I included the two dot leader as well, since I imagine that is more likely to sneak into a URL than an ellipsis):
# U+2026 … \xe2\x80\xa6 HORIZONTAL ELLIPSIS
RewriteRule ^shop/pc/\xe2\x80\xa6/pc/(.*)$ /shop/pc/$1 [R=301,L]
# U+2025 ‥ \xe2\x80\xa5 TWO DOT LEADER
RewriteRule ^shop/pc/\xe2\x80\xa5/pc/(.*)$ /shop/pc/$1 [R=301,L]
Note you may need the [B] flag (see flags) if the browser is percent-escaping the ellipsis.

htaccess partial filename suffix match

As part of a site migration, I have a bunch of old files that I want to redirect to a new site.
The old files all end with _reviews.html, but the new destination is on a different server, without the "_reviews" part of the name, but still ending in .html.
For example:
Old:
www.a.com/my_product1_reviews.html
New:
www.b.com/my_product1.html
I have a few hundred like this so I didn't really want to do them one at a time, but I can't seem to get the correct syntax.
Try this:
RewriteEngine On
RewriteBase /
RewriteRule (.*)_reviews.html$ http://www.b.com/$1.html [L,R=301]

Resources