Hi Karaat,
First, to remove the automatic creation of links, look under the message textarea and uncheck the "Automatically parse links in text" box. That will take care of your www problem!
So, if your visitor types www.example.com/, you want it sent to www.example.com/new/, correct? IMHO, UNLESS you want to use your DocumentRoot for something else, simply change the DocumentRoot of your domain (redirect within cPanel). Okay, that's not your question so I'll go on.
The first exclamation point was a "gudonya," a compliment as you'd performed a miracle ... until we both realized that you are not redirecting everything as you'd intended. The second was a "whew" moment as you didn't need to do anything to satisfy your "do nothing" requirement.
PLEASE wrap your code in [code]...[/code] tags as that preserves the code when quoting for a reply.
Your specification is:
As far as I now understand, the following code seems to fulfil requirements one and three:
- not redirect if the request is already made to mydomain.com/new,
- AND to redirect everything to mydomain.com/new if it is a request to a non-existing file or folder.
- R=301 means permanent redirection.
Then your code is:
Code:
<IfModule mod_rewrite.c>
# Yes, I read your next post but couldn't let that stand :lol:
RewriteEngine On
RewriteRule ^/new/index.php$ - [L]
# passthrough - ditto the comment above, though
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /new/index.php [R=301,L]
# What about the domain request, i.e., no characters?
# Simply change the . to .? (optional anything)
# Then the leading / in the redirection is an absolute redirection
# which is not necessary from the DocumentRoot
</IfModule>
Sometimes I find the last rule written as RewriteRule ^$ /new/ [R=301,L]
Is it better to use . or ^$ (question)?
Really?

Too dumb for me! I prefer (as above) to use .? as there is no need to match anything.
Now I need to redirect requests to my old sites.
OMG, your old site was in the web directory? 
Question:
My new site is actually a Wordpress site. So under new there is htaccess as well. They use
RewriteBase /new/
I fail to understand what that does exactly. I read an explanation that base is used to be added as a prefix to every rewrite rule.
http://randomtype.ca/blog/the-wordpr...ile-explained/ But that didn't seem logical, because the Rewrite rule is still RewriteRule . /new/index.php [L] If the Base would be added the rewrite would read new/new/index.php
.
Well, I have to admit that I can't get my head around any valid reason to use RewriteBase. The RewriteBase directive was created to UNDO a mod_alias Redirect so that mod_rewrite could work on it. WP alters that philosophy and uses it to force the directory in which it resides. RewriteBase simply tells Apache to redirect everything to the directory specified but, if you understand mod_rewrite, you're already doing that with your code.

Originally Posted by
Karaat
Oke, I have caught up a little more and it seems I can remove the IfModule rule (read your rant about it, haha).
You do know that you saved yourself being exposed to the Standard Rant #4 with that comment, don't you?

and

And the first ReWriteRule seems superfluous, because the first RewriteCond handles this. (Wonder why Wordpress guys include it. It is supposed to prevent looping, but I don't know)
That's something relatively new from the WP gang and demonstrates their lack of understanding of mod_rewrite. Okay, I'll cut them some slack for that as they're chasing modules all over the place to get a simple page written from snippets grabbed from "hither and yon." I can't keep track of all their modules (it's not worth my time trying to follow their routing when a simple site search can find the text or identifier I want to modify).
So would this code do?
Code:
# :tup:
RewriteEngine On
RewriteRule ^/web/$ /new/index.php [R=301,L]
# Redirect from the EMPTY web directory to new/index.php.
# Why not eliminate the end anchor so EVERYTHING requested
# from the web directory gets redirected instead?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .? /new/index.php [R=301,L]
That works for me (as modified)! IT would redirect everything requested from web/ to new/index.php then check that a the requested file doesn't exist as a file or as a directory then redirects to new/index.php. That seems to be what you're asking for so you're done (and have learned something while you were at it). Congratulations, you're a mod_rewrite guru ... well, practitioner with a good grasp of what you're doing!

Regards,
DK
Bookmarks