Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule for moved files

         

Einstein2

6:44 pm on Dec 21, 2004 (gmt 0)

10+ Year Member



I want to move my root files one level down (to directory test) in my directort structure. All files should still be accessed through the same URL. Have tried for several hours, but I can't get it working. How do I specify that all files and directories should be rewriten?


# These works for main page and rules.php
#RewriteRule ^$ /mysite.net/ [L]
#RewriteRule ^rules.php$ /mysite.net/rules.php [L]

#Why doesn't this work?
RewriteCond %{HTTP_HOST} ^www\.mysite\.net
RewriteRule ^(.*)$ /test/$1

jdMorgan

6:11 am on Dec 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Einstein2,

Welcome to WebmasterWorld!

#Why doesn't this work?
RewriteCond %{HTTP_HOST} ^www\.mysite\.net
RewriteRule ^(.*)$ /test/$1

If you have other RewriteRules which work, that is, if this is not a "global" failure of mod_rewrite, then I would guess that your rule does not work because it loops. Bear in mind that mod_rewrite in .htaccess behaves recursively, so that any rewritten URL which matches a rule will be rewritten again.

If this is the case, your server error log file will probably show several requests with /test/ prefixes piling up in front of them as the rule is applied multiple times, ending with a server error.

The fix is to explicitly require that the URL has not been previously rewritten before rewriting can proceed:


RewriteCond %{REQUEST_URI} !^/test/
RewriteRule (.*) /test/$1 [L]

Jim

Einstein2

1:06 pm on Dec 22, 2004 (gmt 0)

10+ Year Member



Got u, thanks. That's way I get Internal Server Error after a while. It's an infinit loop.

And it works, thank you so much.