Solved

htaccess mod rewrite syntax, newbie help

Posted on 2004-08-01
2
271 Views
Last Modified: 2010-03-04
Basically I am wondering about some syntax issues.  The below htaccess file works fine for me.
However I have seen things written differently elsewhere and am wondering why it matters.

Here are some examples:
I have seen  mydomain\.com and mydomain.com
When do I need to use the "\"?
I have also seen (.*) and then ^(.*), what is the different here?
Also I have seen is there the ending "$" is not included at all, any reason for this?

If you could check the syntax of my code below and suggest changes let me know.

0 RewriteEngine on
1 RewriteCond %{HTTP_HOST} !^www.maindomain.com$ [NC]
2 RewriteCond %{REQUEST_URI} !^/robots\.txt$
3 RewriteRule (.*) http://www.maindomain.com/$1 [R=301]
4
5 #If robots.txt is requested from anything other than maindomain send new txt file.
6 RewriteCond %{HTTP_HOST} !^maindomain\.com
7 RewriteRule ^robots\.txt /robots_noindex.txt [L]
0
Comment
Question by:killer455
  • 2
2 Comments
 
LVL 18

Accepted Solution

by:
CrYpTiC_MauleR earned 50 total points
ID: 11692025
the \ means the period afterwards will mean a period character otherwise it will mean ANY character, so you must 'escape' it.

^ means the beggining of the string also $ means the end of the string.
0
 
LVL 18

Expert Comment

by:CrYpTiC_MauleR
ID: 11692028
http://regexlib.com/CheatSheet.htm will give you info on regualr expression syntax
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question