Please help a newbie with <IfModule mod_rewrite.c>

Hello all,

I did a search on this but couldnt come up with anything.

I installed wordpress onto my existing site and it rewrote my htaccess file, and basically killed my google traffic.

I looked and cant see the problem, should I just hang tough a little longer? any ideas?

thnx in advance

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^mysite\.net [NC]
RewriteRule (.*) http://www.mysite.net/$1 [R=301,L]

<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

avp,

No wonder I dislike ‘canned code,’ eh?

RewriteEngine On
# RewriteBase /
# NOT needed unless you're using mod_alias to redirect

RewriteCond %{HTTP_HOST} ^mysite\\.net [NC]
RewriteRule [COLOR="Red"]/?[/COLOR](.*) http://www.mysite.net/$1 [R=301,L]
# Okay, just redirects mysite.net to www.mysite.net

# <IfModule mod_rewrite.c>
# That was ONLY to protect you from 500 errors
# if your server did not have mod_rewrite enabled

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# If the file doesn't exist AND
# If the directory doesn't exist THEN
# Redirect to index.php

#</IfModule>
# Ditto

In other words, there is NO reason for this “canned” code to otherwise affect your server.

Regards,

DK

Thank you for your reply. Your comments help me get an idea of the basics functions!

I really want to learn the basics, it is a big challenge for me to just wrap my head around the idea. I have always found coding a little intimidating!

I am not too sure what you mean by “canned code”?

The part that wordpress automatically inserted?

I have been trying to find documentation that spells out in simple terms what

/?(.*)$^, ect do…

Do you have any suggestions for some good online resources?
(I’m afraid that everything in http://httpd.apache.org confuses me):frowning:

I just now noticed your sig…

avp,

It is EXTREMELY bad coding practice to use (.) to capture something for which regex can be written. This is because (.) will capture nothing-to-everything which, for the unwary, will cause looping of the code. In your case, (.*) was appropriate.

The ^/? at the start of regex signifies a start of the {REQUEST_URI} string with an OPTIONAL (the ?) slash (/). This is necessary for different versions of Apache and different locations (.htaccess vs httpd.conf) for the code. It doesn’t hurt to have it and it clears away any problems with ambiguity. In your case, it ensures that any leading slash is NOT sent to example.com//file.name - i.e., it eliminates the possibility of a DOUBLE slash after the domain name.

I trust that the signature tutorial was of assistance and cleared up other points in question for you.

Regards,

DK

Yes it cleared up all my questions! Thanks a million!
:0)