OK. I'm new to Mod_rewrite but I'm really trying here. I've spent the last week reading the documentation, reviewing code, and looking at literally 50 different sites on the net for examples. I'm just not getting it.
Firstly, I wanted to redirect all requests on our server to the www equivalent of the request if it's not present. Yes, I found lots of examples and at least a dozen variations in those examples. They all *seem* to work but there must be a right way to do this. Are any of these even close?
# Rewrite all requests to include the www
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule (.*) [
mysite.com...] [R=301,L]
RewriteCond %{HTTP_HOST} ^\.mysite\.com [NC]
RewriteRule ^(.*)$ [
mysite.org...] [R=301,NC,L]
RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Also, forgive my ignorance, but I notice that thes rules will do the redirection AND then continue on and execute the rest of my rules. That's what I want, but honestly I don't understand WHY that happens as I thought the [L] flag is suppose to make that the last rule. Can someone enlighten me?
Secondly, I started all of this trying to remove new line characters and carriage returns from requests. Mcaffee is scanning our site for PCI compliance and we're failing due to "HTTP Response Splitting".
I tried the following (and a hundred variations thereof) with no success:
# Block out carriage return and new line characters in the HTTP Request
RewriteCond %{THE_REQUEST} ^.*(\\r|\\n|%0A|%0D).* [NC,OR]
# Block out carriage return and new line characters in the Query String variable
RewriteCond %{QUERY_STRING} ^.*(%0A|%0D).* [NC]
RewriteRule ^(.*)$ [
mysite.com...] [R=301,L]
This is the URL their form is submitting:
[
mysite.com...]
I've also noticed that the order that I'm listing the rules has different effects on the result, but again, I can't seem to get it right.
This is my entire .htaccess file:
Options +FollowSymLinks
RewriteEngine On
# Rewrite all requests to include the www
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule (.*) [
mysite.com...] [R=301,L]
# Block out use of illegal or unsafe characters in the HTTP Request
RewriteCond %{THE_REQUEST} ^.*(\\r|\\n|%0A|%0D).* [NC,OR]
# Block out use of New line characters in the Query String variable
RewriteCond %{QUERY_STRING} ^.*(%0A|%0D).* [NC]
RewriteRule ^(.*)$ [
mysite.com...] [R=301,L]
#Serve up the static widget page when the dynamic page is requested - only to deal with sites still linking to our dynamic page
RewriteRule ^cat--Special-Widgets--WIDGETS [
mysite.com...] [R=301,L]
#Rewrite dynamic URLs for SEO
RewriteRule ^smallwidgets.htm /cgi-bin/ccp51/cp-app.cgi?seo=cat--Small-Widgets--SMALLWIDGETS [L]
RewriteRule ^bigwidgets.htm /cgi-bin/ccp51/cp-app.cgi?seo=page--Big-Widgets--BIGWIDGETS [L]
RewriteRule ^shop_by_price--(.*) /cgi-bin/ccp51/cp-app.cgi?seo=shop_by_price--$1
RewriteRule ^cat--(.*) /cgi-bin/ccp51/cp-app.cgi?seo=cat--$1
RewriteRule ^item--(.*) /cgi-bin/ccp51/cp-app.cgi?seo=item--$1
RewriteRule ^page--(.*) /cgi-bin/ccp51/cp-app.cgi?seo=page--$1
RewriteRule ^store /cgi-bin/ccp51/cp-app.cgi?pg=store
RewriteRule ^index$ /cgi-bin/ccp51/cp-app.cgi?pg=ste_index_list
RewriteRule ^az-(.)-(.)$ /cgi-bin/ccp51/cp-app.cgi?pg=ste_index_az&startltr=$1&endltr=$2
RewriteRule ^sitemap.xml$ /cgi-bin/ccp51/cp-app.cgi?pg=ste_sitemap_proc
Any help would be greatly appreciated. I've burned an entire week on this already, crashed our CMS a hundred times, and feel like I'm still no closer to figuring this out.