Forum Moderators: phranque

Message Too Old, No Replies

Same redirect for two different folders

         

randycillekens

8:18 pm on May 7, 2008 (gmt 0)

10+ Year Member



Hi,

I have the following code in my httpd.conf file:

<VirtualHost *>
ServerName websitename
DocumentRoot D:/wwww/websitename
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/admin
RewriteRule !\.(js¦ico¦gif¦jpg¦png¦css)$ /index.php
</VirtualHost>

This works as it should work. Everything except the admin folder is redirected to index.php (with the exception of the js,ico,gif,jpg,png and css file extensions).

What I want is that everything call in the admin folder get redirected to the index.php in the admin folder.

Example:
www.mywebsite.com/admin/test should be redirected to www.mywebsite.com/admin/index.php

I have tried about one thousand possibilities but notting seems to work.

Could somebody give me a hint or maybe just the solutions. (If you give me the sollution, could you please tell me why this is the solution. I don't want to bother you with some kind of question again).

Many thanks,

Randy Cillekens

jdMorgan

10:13 pm on May 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just make a copy of your existing rule, adding the /admin path to the substitution URL, and changing the RewriteCond so that the rule applied when the requested directory *is* /admin. Also, add an [L] flag to all of your rules, unless you have a good reason not to.

RewriteCond %{REQUEST_URI} [b]^/a[/b]dmin
RewriteRule !\.(js¦ico¦gif¦jpg¦png¦css)$ [b]/admin/[/b]index.php [L]

Jim

randycillekens

8:01 pm on May 8, 2008 (gmt 0)

10+ Year Member



Hi jdMorgan,

I allready have tried that. I had the following:

<VirtualHost *>
ServerName websitename
DocumentRoot D:/websites/websitename
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/admin
RewriteRule !\.(js¦ico¦gif¦jpg¦png¦css)$ /index.php [L]
RewriteCond %{REQUEST_URI} ^/admin
RewriteRule !\.(js¦ico¦gif¦jpg¦png¦css)$ /admin/index.php [L]
</VirtualHost>

But when I now go to [websitename...] I get a message that the page doesn't redirect in a right way. Firefefox had noticed that this was a redirect with a never ending loop.

(sorry for my bad translation, the error is in dutch).

I hope you can help me again.

Kind regards,

Randy

randycillekens

8:06 pm on May 8, 2008 (gmt 0)

10+ Year Member



jdMorgan,

I allready figured it out. I had a loop in my code. The index.php called the header function. [header("Location: login");] This causes that he was redirected to [websitename...] And firefox detected a loop I guess. And this is also the reason that I tought it didn't work.

Thank for your help and time!

Randy