No Httpd.config rewrite Uppercase to Lowercase characters - url-rewriting

Unfortunately I do not have acces to Httpd.config file because of my hosting. But I really need to Rewrite all Uppercase characters in URL to lowercase.
Now I have the following:
Redirect 301 /korting/CompAny1/ http://www.web.nl/korting/company1/
Redirect 301 /korting/CompaNy2/ http://www.web.nl/korting/company2/
Is there a rewrite rule to lowercase everything? I have a Wordpress installation so a plugin or php script would also be fine....
This question is asked a lot of times and a lot of answers don't work or require
Httpd.config

Finally!!
An answer that didn't broke my site and actually works!
EDIT: unfortunately after a few minutes my site broke down......
# Skip next two rules if lowercasing in progress (Remove this rule if case-conversion plug-in below is removed)
RewriteCond %{ENV:qLow} ^yes$ [NC]
RewriteRule . - [S=2]
# Prevent recursion and over-writing of myURI and myQS
RewriteCond %{ENV:qRed} ^yes$ [NC]
RewriteRule .? - [L]
# Get the client-requested full URI and full query string
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ (/[^?]*)(\?[^\ ]*)?\ HTTP/
RewriteRule .? - [E=myURI:%1,E=myQS:%2]
# Uppercase to lowercase conversion plug-in (This section, along with the first noted rule above, may be removed if not needed or wanted) Skip next 28 rules if no uppercase letters in URL
RewriteCond %{ENV:myURI} ![A-Z]
RewriteRule .? - [S=28]
# Else swap them out, one at a time
RewriteCond %{ENV:myURI} ^([^A]*)A(.*)$
RewriteRule . - [E=myURI:%1a%2]
RewriteCond %{ENV:myURI} ^([^B]*)B(.*)$
RewriteRule . - [E=myURI:%1b%2]
RewriteCond %{ENV:myURI} ^([^C]*)C(.*)$
RewriteRule . - [E=myURI:%1c%2]
RewriteCond %{ENV:myURI} ^([^D]*)D(.*)$
RewriteRule . - [E=myURI:%1d%2]
RewriteCond %{ENV:myURI} ^([^E]*)E(.*)$
RewriteRule . - [E=myURI:%1e%2]
RewriteCond %{ENV:myURI} ^([^F]*)F(.*)$
RewriteRule . - [E=myURI:%1f%2]
RewriteCond %{ENV:myURI} ^([^G]*)G(.*)$
RewriteRule . - [E=myURI:%1g%2]
RewriteCond %{ENV:myURI} ^([^H]*)H(.*)$
RewriteRule . - [E=myURI:%1h%2]
RewriteCond %{ENV:myURI} ^([^I]*)I(.*)$
RewriteRule . - [E=myURI:%1i%2]
RewriteCond %{ENV:myURI} ^([^J]*)J(.*)$
RewriteRule . - [E=myURI:%1j%2]
RewriteCond %{ENV:myURI} ^([^K]*)K(.*)$
RewriteRule . - [E=myURI:%1k%2]
RewriteCond %{ENV:myURI} ^([^L]*)L(.*)$
RewriteRule . - [E=myURI:%1l%2]
RewriteCond %{ENV:myURI} ^([^M]*)M(.*)$
RewriteRule . - [E=myURI:%1m%2]
RewriteCond %{ENV:myURI} ^([^N]*)N(.*)$
RewriteRule . - [E=myURI:%1n%2]
RewriteCond %{ENV:myURI} ^([^O]*)O(.*)$
RewriteRule . - [E=myURI:%1o%2]
RewriteCond %{ENV:myURI} ^([^P]*)P(.*)$
RewriteRule . - [E=myURI:%1p%2]
RewriteCond %{ENV:myURI} ^([^Q]*)Q(.*)$
RewriteRule . - [E=myURI:%1q%2]
RewriteCond %{ENV:myURI} ^([^R]*)R(.*)$
RewriteRule . - [E=myURI:%1r%2]
RewriteCond %{ENV:myURI} ^([^S]*)S(.*)$
RewriteRule . - [E=myURI:%1s%2]
RewriteCond %{ENV:myURI} ^([^T]*)T(.*)$
RewriteRule . - [E=myURI:%1t%2]
RewriteCond %{ENV:myURI} ^([^U]*)U(.*)$
RewriteRule . - [E=myURI:%1u%2]
RewriteCond %{ENV:myURI} ^([^V]*)V(.*)$
RewriteRule . - [E=myURI:%1v%2]
RewriteCond %{ENV:myURI} ^([^W]*)W(.*)$
RewriteRule . - [E=myURI:%1w%2]
RewriteCond %{ENV:myURI} ^([^X]*)X(.*)$
RewriteRule . - [E=myURI:%1x%2]
RewriteCond %{ENV:myURI} ^([^Y]*)Y(.*)$
RewriteRule . - [E=myURI:%1y%2]
RewriteCond %{ENV:myURI} ^([^Z]*)Z(.*)$
RewriteRule . - [E=myURI:%1z%2]
# Set lowercasing-in-progress flag
RewriteRule . - [E=qLow:yes]
# If any uppercase characters remain, re-start mod_rewrite processing from the beginning
RewriteCond %{ENV:myURI} [A-Z]
RewriteRule . - [N]
# If any characters were lowercased, set redirect required flag and reset lowercasing-in-progress flag (S=28 from above lands here)
RewriteCond %{ENV:qLow} ^yes$ [NC]
RewriteRule . - [E=qRed:yes,E=qLow:done]
# End Uppercase to lowercase conversion plug-in
RewriteCond %{ENV:qRed} ^yes$ [NC]
RewriteRule .? http://%{HTTP_HOST}%{ENV:myURI}%{ENV:myQS} [R=301,L]

Related

Remove/Redirect public/index.php from url to prevent duplicate urls

Hello i am facing issue to remove the public/index.php from url. Remove/Redirect index.php from url to prevent duplicate urls
This link really helps me to remove index.php form url but i am not able to remove public/index.php from url. Here is my below htacces code
RewriteEngine On
#REmove index.php from url starts
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php[^/] /$1? [L,R=302,NC,NE]
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php(?:/(.*))?$ /$1$2? [L,R=302,NC,NE]
#Remove index.php from url ends
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
But when i add this below code to remove public/index.php in htaccess its not working :-
RewriteCond %{THE_REQUEST} /public/index\.php [NC]
RewriteRule ^(.*?)public/index\.php[^/] /$1? [L,R=302,NC,NE]
RewriteCond %{THE_REQUEST} /public/index\.php [NC]
RewriteRule ^(.*?)public/index\.php(?:/(.*))?$ /$1$2? [L,R=302,NC,NE]
Example urls that should be redirected:
mydomain.com/public/index.php/something should be redirected to mydomain.com/something (something could be anything - can contain any characters)
mydomain.com/public/index.php should be redirected to mydomain.com
mydomain.com/index.php?anything should be redirected to mydomain.com?anything (anything can contain any characters)
Pleae help me how to resolve this issue.
You may use this rule inside public/.htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} /public/index\.php(?:[/?](\S+))?\sHTTP [NC]
RewriteRule ^ /%1 [L,R=301,NE]
RewriteCond %{THE_REQUEST} /public/(\S*)\sHTTP [NC]
RewriteRule ^ /%1 [L,R=301,NE]
# other rules below this line
Additionally use this code in site root .htaccess:
RewriteEngine On
# remove /index.php
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.php$ [NC]
RewriteRule ^ %1 [L,R=301,NE]
RewriteRule ^ public%{REQUEST_URI} [L]

Setting a cookie based on query string for split testing

If a query string is detected, I want to update/set a cookie so a particular dir is used for that browser session or until the query string is explicitly set again. Visitor is not to see the dir, but instead will just see http://mydomain.com/.
This is what I have so far but it doesn't work as expected. Pretty sure I'm writing the logic wrong, but not sure where.
RewriteCond %{QUERY_STRING} splittest=(A|B)
RewriteRule splittest=(A|B) [CO=splittest:$1:%{HTTP_HOST}:0:/,L]
RewriteCond %{QUERY_STRING} splittest=A [OR]
RewriteCond %{HTTP_COOKIE} splittest=A
# Split test A
RewriteRule ^(.*)$ A/$1 [L]
# Split test B
RewriteRule ^(.*)$ B/$1 [L]
Try this. I'm assuming your .htaccess is located at web root / directory.
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} splittest=A [NC]
RewriteRule ^ - [CO=splittest:A:%{HTTP_HOST}:0:/]
RewriteCond %{QUERY_STRING} splittest=B [NC]
RewriteRule ^ - [CO=splittest:B:%{HTTP_HOST}:0:/]
RewriteCond %{QUERY_STRING} splittest=A [NC,OR]
RewriteCond %{HTTP_COOKIE} splittest=A [NC]
# Split test A
RewriteRule ^(.*)$ A/$1 [L]
# Split test B
RewriteRule ^(.*)$ B/$1 [L]

Mod_Rewrite Exclude a url (URI Exception)

I am using this mod-rewrite rule to redirect the just the homepage of my site to the /it/ sub-directory on the same site.
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RedirectMatch 301 ^/$ http://www.example.com/it/
However, I want to exempt this url from being redirected
http://www.example.com/?act=25
How can I write an exempt condition to do this?
Found a solution
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{QUERY_STRING} !^act=(.*)$ [NC]
RewriteRule ^$ http://www.example.com/it/
Oh, and RewriteCond does not work with RedirectMatch in case you didn't know (I didn't and wasted hrs because of it)

Mod_rewrite wildcard subdomains. Simple question regarding not so simple rewrite rules

basically I'm trying to do this:
subdomain.domain.com -> domain.com/account?user=subdomain
So far so good. I have found this code to do it and works perfect:
RewriteCond %{HTTP_HOST} !^domain\.com [NC]
RewriteCond %{ENV:REDIRECT_SUBDOMAIN} =""
RewriteCond %{HTTP_HOST} ([^.]+)\.domain\.com$
RewriteRule ^(.*)$ account.php?user=%1 [E=SUBDOMAIN:%1,L]
RewriteRule ^ - [E=SUBDOMAIN:%{ENV:REDIRECT_SUBDOMAIN},L]
Now I'm trying to add one more simple rule to it (marked with *). Adding this new rule makes everything fall apart. Nothing works anymore
RewriteCond %{HTTP_HOST} !^domain\.com [NC]
RewriteCond %{ENV:REDIRECT_SUBDOMAIN} =""
RewriteCond %{HTTP_HOST} ([^.]+)\.domain\.com$
* RewriteRule ^/somepage http://domain.com/anotherpage [E=SUBDOMAIN:%1,L]
RewriteRule ^(.*)$ account.php?user=%1 [E=SUBDOMAIN:%1,L]
RewriteRule ^ - [E=SUBDOMAIN:%{ENV:REDIRECT_SUBDOMAIN},L]
Any idea what is going on and how to correct it ?
Thank you
Catalin
A RewriteRule is subject to the current set of RewriteCond conditions.
So you will have to do something like that:
RewriteCond
RewriteCond
RewriteRule
RewriteCond
RewriteCond
RewriteRule

Using mod_rewrite with multiple Drupal installations

I have a website with Drupal installed in a subfolder /drupal. This instance needs to handle all URLs for the site, which it does successfully with the rules below:
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} !^131.216.164.200:10011$ [NC]
RewriteRule .* http://131.216.164.200:10011/ [L,R=301]
RewriteRule ^$ drupal/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/drupal%{REQUEST_URI} -f
RewriteRule .* drupal/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* drupal/index.php?q=$0 [QSA]
However, I now need to add another Drupal folder, /otherdrupal, which will handle only URLs beginning with /something1 or /something2. What I've tried is modifying the rules to this:
RewriteCond %{HTTP_HOST} !^131.216.164.200:10011$ [NC]
RewriteRule .* http://131.216.164.200:10011/ [L,R=301]
RewriteRule ^(something1|something2)$ otherdrupal/index.php [L]
RewriteRule ^$ drupal/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/drupal%{REQUEST_URI} -f
RewriteRule .* drupal/$0 [L]
RewriteCond %{DOCUMENT_ROOT}/otherdrupal%{REQUEST_URI} -f
RewriteRule .* otherdrupal/$0 [L]
But mod_rewrite is not gonna make it that easy...
(P.S. I'm aware of Drupal's multi-site feature, but assume that the second Drupal instance may be any web application that handles URLs the same way as Drupal does, e.g. with a q URL parameter.)
I figured it out. My working .htaccess file:
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} !^131.216.164.200:10011$ [NC]
RewriteRule .* http://131.216.164.200:10011/ [L,R=301]
RewriteRule ^$ drupal/index.php [L]
RewriteCond %{REQUEST_URI} ^(/something1|/something2)
RewriteRule .* otherdrupal/index.php?r=$1 [L,QSA]
RewriteCond %{DOCUMENT_ROOT}/drupal%{REQUEST_URI} -f
RewriteRule .* drupal/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* drupal/index.php?q=$0 [QSA]

Resources