Forum Moderators: phranque
I sucessfully managed to solve the canonical issue via .htaccess so far. Now I discovered that google indexes some ulrs with my alias domain, which I find a bit suspicious.
this is my current entry:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain\.de [nc]
RewriteRule (.*) [mydomain.de...] [R=301,L]
In order to also redirect my alias-domain, I tried to double the second line and change it to 'myotherdomain' accordingly, but that doesn't work. I assume some 'or' operator or so is mising, but I have no idea about the exact syntax.
P.S. I found that so many postings in here deal with htaccess, and I feel a bit ashamed for not having done any intensive research before posting, but I find the notation so cryptic and the role of htaccess for my running web-application is so fundamental, that I'd hesitate to solve this issue by trial and error. A tutorial on the very basic and repeatedly asked questions (like mine) would be really helpful.
Perhaps what you need to know is this: A RewriteCond affects only the single following RewriteRule, and not any subsequent rules. So, you would need to double both lines, not just the second one.
Because mod_rewrite's function is fundamental to the operation of many sites, time spent studying the documentation is worthwhile. For that reason I refer you to the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Time spent learning regular expressions, a critical "part" of using mod_rewrite, is useful with many other programming languages; The POSIX regular expressions library is bundled with almost all modern operating systems, and is used by many modern scripting languages, such as PERL, PHP, and many others.
As for posting the answers to "common" questions, the problem is that every problem varies, as does every server configuration, as well as the desires of the Webmaster. For that reason, all we can do is to post examples, and leave it to the studious Webmaster to modify the code accordingly, asking for help if problems are encountered during testing. BTW, a good method for testing is to set up a "test" subdomain on your server, so as not to affect the operation of your "real" Web site -- And of course, this can be done with ... mod_rewrite. ;)
Jim
> So, you would need to double both lines,
Yes, I tried that and it seems to work.
so this is my new notation:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain\.de [nc]
RewriteRule (.*) [mydomain.de...] [R=301,L]
RewriteCond %{HTTP_HOST} ^myotherdomain\.de [nc]
RewriteRule (.*) [mydomain.de...] [R=301,L]
RewriteCond %{HTTP_HOST} ^www.myotherdomain\.de [nc]
RewriteRule (.*) [mydomain.de...] [R=301,L]
Now, what about mydomain.de/index.html? Is it recommended to redirect that one as well concerning duplicate content issues with google?
> regular expressions, a critical "part" of using mod_rewrite, is useful with many other programming languages;
How true. I recently tried to analyse my original logfiles a bit using php. All those dozens of lines trying to extract e.g. the referrer-search-phrases could presumably be substituted by a single preg-match command with the appropriate posix-syntax. Sometimes I wish a was a few years (decades!) younger;)
I read quite a few cryptic texts in the past, from Freges "Begriffsschrift" to Goedels proof in its original notation, but as time goes by this becomes more and more difficult. As a matter of fact this posix-stuff is best learned with the help of a good human teacher. Autodidaction fails in my age meanwhile, and it is a pitty, no such courses are offered in my region.
Once again thx for taking your time to answer, very much appreciated.
> Now, what about mydomain.de/index.html?
You can redirect that to "/" but there is a trick to it. You must use THE_REQUEST to avoid an "infinite" mod_rewrite/DiretoryIndex loop:
RewriteEngine on
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html
RewriteCond ^index\.html$ http://www.mydomain.de/ [R=301,L]
#
RewriteCond %{HTTP_HOST} ^(mydomain¦(www\.)?myotherdomain)\.de [NC]
RewriteRule (.*) http://www.mydomain.de/$1 [R=301,L]
Gödels theorem was the subject of a book I once read, called "Gödel, Escher, Bach -- An eternal golden braid" by Douglas Hofstadter. Like Gödels theorem, regular expressions can be mastered through repeated study and application. Mod_rewrite combines logic and pattern-matching to attain its compact power.
Our forum charter [webmasterworld.com] includes a link to a concise regular expressions tutorial. I have grey hair, but it seems usable to me... :)
Jim
> "Gödel, Escher, Bach -- An eternal golden braid" by Douglas Hofstadter.
That small little booklet form Nagel and Newman, to which Hofstadter refers in his appendix and (intro-)text, is much more concise and readable.
Goedel primarily attacked Russel and Whitehead's claim to have established a complete and consistent representation of arithmetics in their "Principia Mathematica" based on purely formal logic. Those, in turn, took Frege's ideas of a logical "language" as one of the central cores of their framework. All the issues discussed in this dispute are quite fundamental for the "semantic" principles of any computer language, long before Chomsky laid the basis for an appropriate "syntax." Given all the speed and acceleration of current technical development it is sometimes quite refreshing to lean back, take breath, and recapitulate how all this progress is embedded in a broader historical process. Slows down things tremendously.