I have this code in my .htaccess file. I have forgotten what each line of code is doing!
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\\.sitename\\.co.uk$ [NC]
RewriteRule .? http://www.sitename.co.uk%{REQUEST_URI} [R=301,L]
Options -MultiViews
RewriteCond %{REQUEST_URI} ^/productcode
RewriteCond %{QUERY_STRING} product=([a-zA-Z0-9-]+)&code=([a-zA-Z0-9-]+)
RewriteRule .? /%1%2? [L,R=301]
We decided not to use PHP on the website. I think this means I can delete this code from the .htaccess file, right?:
Options -MultiViews
RewriteCond %{REQUEST_URI} ^/productcode
RewriteCond %{QUERY_STRING} product=([a-zA-Z0-9-]+)&code=([a-zA-Z0-9-]+)
RewriteRule .? /%1%2? [L,R=301]
Can you also tell me what this code is doing, please?:
RewriteCond %{HTTP_HOST} !^www\\.sitename\\.co.uk$ [NC]
RewriteRule .? http://www.sitename.co.uk%{REQUEST_URI} [R=301,L]
The reason for getting rid of the PHP rewrite code is we do not need it and it is causing some errors in Google Analytics (suggesting we have some PHP files with errors when we do not).
I look forward to your comments,
Matt.
dklynn
February 20, 2014, 10:51pm
2
Hi Matt,
Oh, my! I just (politely) chastised another member for not knowing what his code is doing … but you do get credit for asking.
MatthewBOnline:
I have this code in my .htaccess file. I have forgotten what each line of code is doing!
RewriteEngine on
[indent]Ensures that mod_rewrite is NOT in it's "Comment Mode"[/indent]
RewriteCond %{HTTP_HOST} !^www\\.sitename\\.co.uk$ [NC]
[indent]Tests whether the {HTTP_HOST} is NOT www.sitename.co.uk without regard
to the case (No Case) - but you forgot to escape the . before uk.[/indent]
RewriteRule .? http://www.sitename.co.uk%{REQUEST_URI} [R=301,L]
[indent]If the RewriteCond is TRUE, redirect the request to the www'd domain
with a permanent redirect.[/indent]
Options -MultiViews
[indent]A server directive (I put those at the top to keep the mod_rewrite code contiguous),
this tells the server NOT to capture path names and look for files of that name in the path,
i.e., the {REQUEST_URI} should look in the specified directory for the specified file.[/indent]
RewriteCond %{REQUEST_URI} ^/productcode
[indent]If the request starts with [size=6]/[/size]productcode - which should cause problems
with Apache 2.x servers as they do not like a leading / after the start anchor (at least this
was the crippling change when converting from an Apache 1.x to the early Apache 2.x servers).[/indent]
RewriteCond %{QUERY_STRING} product=([a-zA-Z0-9-]+)&code=([a-zA-Z0-9-]+)
[indent]AND, if the query string [I]contains [/I]product={at least one letter, digit or -}
[B][I]followed by[/I][/B] & [B][I]followed by[/I][/B] code={at least one letter, digit or -};
WARNING: the order of your key/value pairs is critical! Also, mod_rewrite prefers
dashes as dashes to be the first character in the character range definition albeit
it should not be confused as a metacharacter as the last character, either.[/indent]
RewriteRule .? /%1%2? [L,R=301]
[indent]Permanently redirect to the server's root (or DocumentRoot if not in the server - SECURITY issue) {product value} / {code value}.
NOTE: This will require another redirection as the server is not likely to be able to serve anything using product and code values.[/indent]
We decided not to use PHP on the website. I think this means I can delete this code from the .htaccess file, right?:
Sorry, without knowing more about what you’re doing, there’s no way to tell.
Options -MultiViews
RewriteCond %{REQUEST_URI} ^/productcode
RewriteCond %{QUERY_STRING} product=([a-zA-Z0-9-]+)&code=([a-zA-Z0-9-]+)
RewriteRule .? /%1%2? [L,R=301]
As above.
Can you also tell me what this code is doing, please?:
RewriteCond %{HTTP_HOST} !^www\\.sitename\\.co.uk$ [NC]
RewriteRule .? http://www.sitename.co.uk%{REQUEST_URI} [R=301,L]
As above, it’s forcing www on the domain name.
The reason for getting rid of the PHP rewrite code is we do not need it and it is causing some errors in Google Analytics (suggesting we have some PHP files with errors when we do not).
That’s a reason to change all your code? Oh, well.
I look forward to your comments,
Matt.
Regards,
DK