Forum Moderators: phranque
I would like to do the following in my .htaccess file:
REDIRECT http://example.com/yyy/zzz... TO http://example.com/
EXCEPT IF yyy = documents
I have tried some variants on
RedirectMatch permanent /!(documents)/* http://example.com/
but it doesn't work. Any suggestions?
Please note that I do NOT want to redirect anything of the form http://example.com/yyy or http://example.com/yyy/ -- i.e., I only want to redirect if there is something after that next slash.
thanks so much!
[edited by: jdMorgan at 3:36 am (utc) on Sep. 5, 2007]
[edit reason] example.com [/edit]
Options +FollowSymLinks
RewriteEngine on
#
# Externally redirect /dir1/<something> to example.com/ unless dir1=documents
RewriteCond %{REQUEST_URI} !^/documents/
RewriteRule ^[^/]+/. http://example.com/ [R=301,L]
If you don't have any other working mod_rewrite code, you will need either the second line above (RewriteEngine), or both the first (Options) and the second line. Try it with only the second line, and add the first if you get a server error. If you've already got other working rules, then you'll already have one or both of those lines in the file, and there is no need to repeat them.
Jim
Thanks so much for your comments -- especially yours, jdMorgan, as I appreciated your explanation.
Unfortunately, this is conflicting with a couple other rules I've made up. My complete htaccess file is the following:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /base/htdocs
RewriteCond %{REQUEST_URI}!^/documents/$ [NC]
RewriteRule ^[^/]+/. http://example.com/ [R=301,L] # (1)
RewriteRule ^([^/\.]+)/?$ /mediawiki/index.php/$1 [NC,L] # (2)
RewriteRule ^/?$ /mediawiki/index.php/startPage [NC,L] # (3)
(1) is your solution
(2) maps example.com/yyy to example.com/mediawiki/index.php/yyy
(3) maps example.com/ to example.com/mediawiki/index.php/startPage
The problem is that all three together cause http://example.com/ to go through an infinite loop and never stop at any one website.
Any ideas what is happening? I'll admit that I don't quite understand (2), which was a suggestion from someone else.
Thanks so much!
You need to be careful and fully-specify your requirements before coding...
Jim
[edited by: jdMorgan at 1:37 am (utc) on Sep. 6, 2007]