Welcome to WebmasterWorld Guest from 54.159.50.111

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

problem with modrewrite

     
9:27 pm on Nov 17, 2002 (gmt 0)

New User

10+ Year Member

joined:Nov 17, 2002
posts:7
votes: 0


If there is a request for a.htm, I can serve b.htm using
RewriteRule ^a\.htm$ /b.htm

but I really want to serve a page from a subdirectory
like dir/b.htm

I tried
RewriteRule ^a\.htm$ /dir/b.htm

but I can't get it to work

I've read the documentation over & over & I can't figure out what to do

Can someone help me? Thanks!

9:47 pm on Nov 17, 2002 (gmt 0)

Preferred Member

10+ Year Member

joined:Oct 28, 2002
posts:492
votes: 0


I'm not a wizard with mod_rewrite, but shouldn't it be

RewriteRule ^/a\.htm$ /dir/b.htm

René.

9:55 pm on Nov 17, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


alwaysonline,

Welcome to WebmasterWorld!

If you are using mod_rewrite in .htaccess for per-directory rewrites, leave the leading slash off the path in the left side. If you are using mod_rewrite in httpd.conf, then include the slash in both sides.

This should work in a per-directory .htaccess environment:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^a\.htm$ /dir/b.htm

You may also need to use RewriteBase if your filespath does not start in the same directory as your site's index page.

What happens when you try to test this? Are there any entries in your raw error log file?

Jim

12:30 am on Nov 19, 2002 (gmt 0)

New User

10+ Year Member

joined:Nov 17, 2002
posts:7
votes: 0


thanks -

tried it, still getting a 404

says it can't find dir/b.htm

any more thoughts? thanks

12:52 am on Nov 19, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


alwaysonline,

If it says it can't find yourdomain/dir/b.htm, the the rewrite is working but it can't find that subdirectory for some reason. Can you access yourdomain/dir/b.htm directly?

Your rewrite rule is correct, so something else is happening. If you have more rewrite rules ahead of or following the one we're talking about, you may want to add the [L]ast flag to some or all of your rules. Also, check the description of RewriteBase and make sure it does not apply to your case.

Jim

1:03 am on Nov 19, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 22, 2002
posts:1782
votes: 0


The webserver´s error message surely is a bit more precise. Looking at the absolute path that is probably given there will help you determine if you need to set the RewriteBase directive.

It is always helpful to post error messages. Something that might not look relevant to you might be just the thing that helps Jim know whats wrong. :)

Andreas

2:40 pm on Nov 19, 2002 (gmt 0)

New User

10+ Year Member

joined:Nov 17, 2002
posts:7
votes: 0


It doesn't seem to be related to the subdirectory.

I put both files in the same directory and
RewriteRule ^a\.htm$ /b.htm
didn't work either.

The only msg I get is
The requested URL /b.htm was not found on this server.

I am doing is in a secure environment so the path is:
[myhostssecure.com...]
but the hosting company says it should work in the secure environment (modrewrite is working ok in std environ)

(hosting company is pair, so I tend to trust them)

4:01 pm on Nov 19, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 22, 2002
posts:1782
votes: 0


Given a request GET /path/to/aaron.html

RewriteRule aaron.html jesse.html

will result in GET* /path/to/jesse.html while

RewriteRule aaron.html /jesse.html

will result in GET* /jesse.html.

If you want the directory prefix that got removed by mod_rewrite in .htaccess context prior to matching to be added after the rewrite is done your substitution may not start with a slash. If it does start with a slash this substitution is taken as an absolute path.

Andreas


* Note that this will be an internal redirect unless you specify the R flag. So there is really no HTTP request using the GET method.
3:09 pm on Nov 20, 2002 (gmt 0)

New User

10+ Year Member

joined:Nov 17, 2002
posts:7
votes: 0


Thanks,

I tried this:
RewriteEngine on
RewriteRule ^a\.htm$ b.htm

and got this error msg:
The requested URL /usr/home/myid/public_ssl/b.htm was not found on this server.

But b.htm is there

I wonder if symbolic links are causing problems?

/bin/pwd for public_ssl gives:
/usr/www/users/myid

10:56 pm on Nov 20, 2002 (gmt 0)

New User

10+ Year Member

joined:Nov 17, 2002
posts:7
votes: 0


anyone got any ideas?

thanks

12:11 am on Nov 21, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 22, 2002
posts:1782
votes: 0


If you can access /usr/home/myid/public_ssl/b.htm via your server without any rewrite rules then you can rule out the symlink as the cause of error.

Is /usr/home/myid/public_ssl your DocumentRoot?

Can the user apache runs as access the file?

To check you could always su to the user apache is running as and check whether you can read it.

If you do cd /usr/home/myid/public_ssl pwd should display /usr/home/myid/public_ssl while doing cd /usr/www/users/myid/public_ssl pwd should display /usr/www/users/myid/public_ssl.

Check whether the symlink points to the right directory using ls -l.

Just some random ideas.

Andreas

12:11 am on Nov 21, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


alwaysonline,

I suggest you investigate using the RewriteBase directive of mod_rewrite, as I posted in msg #3 above.

If you can't use RewriteBase to fix your problem, we are going to need more detail on what your paths look like, and what your environment is like. I think you are saying that you are trying to redirect from both http and https to a file in a subdirectory, and you are getting different results between http and https, but it's not clear.

Your problem requires attention to detail. Please describe exactly what your situation is as far as http/https, and the structure of your directories and paths from both views (if applicable).

Jim

4:27 pm on Nov 22, 2002 (gmt 0)

New User

10+ Year Member

joined:Nov 17, 2002
posts:7
votes: 0


I can now replicate the same prob in a non-secure environment, so I suspect it is independent of secure/nonsecure.

I can access a.htm & b.htm this way:
wwwXXX.myhost.com/myid/a.htm
wwwXXX.myhost.com/myid/b.thm

If I insert this:
RewriteEngine on
RewriteRule ^a\.htm$ b.htm

then
wwwXXX.myhost.com/myid/a.htm

gives one of these 2 error mssages (not always the same one)

404 page not found

or
/usr/home/myid/public_html/b.htm not found

but that is where it is

6:15 pm on Nov 23, 2002 (gmt 0)

New User

10+ Year Member

joined:Nov 17, 2002
posts:7
votes: 0


I tried

RewriteBase /myid

It works!

Jim & Andreas, thanks for all of your help!

6:23 pm on Nov 23, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


alwaysonline,

Cool! Glad to hear it!

Jim