Forum Moderators: phranque

Message Too Old, No Replies

301 redirect all except one directory

Can I do this?

         

trillianjedi

6:36 pm on Sep 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have one server not on WWW duty but requires example.com to point at it.

So I have example.com resolving to it's IP, and I need to redirect any web requests to the www box.

So far, easy.

Problem is that I need to access phpmyadmin on this box from time to time, so I do need access to example.com/phpmyadmin

Is there any way I can do a conditional 301?

So if the requested URL isn't /phpmyadminXYZ then 301 to www.example. com?

Thanks,

TJ

jd01

6:42 pm on Sep 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just answered that while you were posting.

here: [webmasterworld.com...]

Justin

trillianjedi

8:58 pm on Sep 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the link from the other thread JD.

I couldn't actually get this to work. The directory I don't want the redirect on is /phpmyadmin, so I tried this:-

RewriteEngine on
RewriteRule!^/phpmyadmin - [C]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

But it's still redirecting everything.

Any thoughts?

TJ

jdMorgan

9:04 pm on Sep 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is this code in httpd.conf, or in .htaccess?

Jim

trillianjedi

9:21 pm on Sep 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey Jim.

In .htaccess.

It's the only code in there - this box does nothing else web-wise.

Thanks,

TJ

jd01

10:45 pm on Sep 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem is the / (it is stripped before comparrison in the .htaccess.)

RewriteRule !^phpmyadmin - [C]

Justin

jdMorgan

10:51 pm on Sep 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or, a bit more efficient:

RewriteEngine on
RewriteCond $1 !^phpmyadmin
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Jim

trillianjedi

11:07 am on Sep 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you very much guys, works a treat now.

TJ