Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule is matching my internal (Unix) file path!

Problem started when I got a dedicated server...

         

MichaelBluejay

7:29 am on Jul 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Someone deep linked to one of my pages but included a "]" character in the url, leading visitors to my 404 page instead of the content page. i.e., <http://mydomain.com/subdir/page.html]> No problem, I figured I'd just create a rule to filter out any trailing "]" characters, with the .htaccess file that's in the <subdir> folder:

RewriteRule (.*)]$ $1 [L,R]

But lo and behold, when I test it my browser redirects to:

http://mydomain.com/home/user/mydomain.com/subdir/page.html

What the heck? Okay, so I figure I'll just match only what comes after the "subdir":

RewriteRule subdir/(.*)]$ $1 [L,R]

But when I do that no match happens at all. I type <http://mydomain.com/subdir/page.html]> in my browser and just get a 404 error, no redirect.

What's going on here?

jdMorgan

1:46 pm on Jul 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You've got an Alias working against you here, or possibly a server config problem.

Try using


RewriteBase /home/user/mydomain.com/

to tell mod_rewrite how you got to the current location -- See RewriteBase directive in mod_rewrite docs for more info.

The RewriteBase path shown above may need some tweaking. It should include anything "extra or unexpected" that you find in the path reported to have caused an error. I'm not sure if I got it exactly right.

[added] I strongly suggest that you use [R=301,L] to generate a 301 redirect in this case, rather than the default 302. [/added]

Jim

MichaelBluejay

10:07 pm on Jul 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Ah, RewriteBase. I played around and what fixed it was:

RewriteBase /subdir/

Thanks much for the help.