homepage Welcome to WebmasterWorld Guest from 54.167.144.202
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
problem with modrewrite
alwaysonline

10+ Year Member



 
Msg#: 47 posted 9:27 pm on Nov 17, 2002 (gmt 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!

 

seindal

10+ Year Member



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

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

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

René.

jdMorgan

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



 
Msg#: 47 posted 9:55 pm on Nov 17, 2002 (gmt 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

alwaysonline

10+ Year Member



 
Msg#: 47 posted 12:30 am on Nov 19, 2002 (gmt 0)

thanks -

tried it, still getting a 404

says it can't find dir/b.htm

any more thoughts? thanks

jdMorgan

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



 
Msg#: 47 posted 12:52 am on Nov 19, 2002 (gmt 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

andreasfriedrich

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 47 posted 1:03 am on Nov 19, 2002 (gmt 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

alwaysonline

10+ Year Member



 
Msg#: 47 posted 2:40 pm on Nov 19, 2002 (gmt 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:
https://myhostssecure.com/myuserid
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)

andreasfriedrich

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 47 posted 4:01 pm on Nov 19, 2002 (gmt 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.
alwaysonline

10+ Year Member



 
Msg#: 47 posted 3:09 pm on Nov 20, 2002 (gmt 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

alwaysonline

10+ Year Member



 
Msg#: 47 posted 10:56 pm on Nov 20, 2002 (gmt 0)

anyone got any ideas?

thanks

andreasfriedrich

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 47 posted 12:11 am on Nov 21, 2002 (gmt 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

jdMorgan

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



 
Msg#: 47 posted 12:11 am on Nov 21, 2002 (gmt 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

alwaysonline

10+ Year Member



 
Msg#: 47 posted 4:27 pm on Nov 22, 2002 (gmt 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

alwaysonline

10+ Year Member



 
Msg#: 47 posted 6:15 pm on Nov 23, 2002 (gmt 0)

I tried

RewriteBase /myid

It works!

Jim & Andreas, thanks for all of your help!

jdMorgan

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



 
Msg#: 47 posted 6:23 pm on Nov 23, 2002 (gmt 0)

alwaysonline,

Cool! Glad to hear it!

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved