Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mod_rewrite help

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am having a problem getting mod_rewrite to work.

I have the following:

RewriteEngine on
RewriteRule ^/somepath(.*) $1

For the requested URL
I get the following in the rewrite log:
(2) init rewrite engine with requested uri /somepath/manual/mod/mod_rewrite.html
(3) applying pattern '^/somepath(.*)' to uri '/somepath/manual/mod/mod_rewrite.html'
(2) rewrite /somepath/manual/mod/mod_rewrite.html -> /manual/mod/mod_rewrite.html
(2) local path result: /manual/mod/mod_rewrite.html
(2) init rewrite engine with requested uri /error/HTTP_BAD_REQUEST.html.var {...and the error continues}

It appears to get the correct substitution but it just doesn't work. If I put a [R] at the end of the rule, the redirect does work...

I have spent a long time trying to figure out why, but with no success.

Hopefully someone can help :)

Regards
Colin
 
I believe the output of your rewrite is an absolute system path, not a path relative to your document root. That would be why the "[R]" directive works -- it tells the browser to ask for the new file directly.

Add the RewriteBase directive with the filesystem path to your document root. Put it before your RewriteRule line.

______________________________________________________________________
TANSTAAFL!
 
Thanks for that (sleipnir214?)

Gave it a try... I am setting the rule in the main httpd config file so got the following error:
>>> RewriteBase: only valid in per-directory config files.

Any more suggestions would be greatly appreciated and I will give them a try.

Regards
Colin
 
RewriteBase can only apply to rewrite operations for a single directory, not for a whole site. If my picture of your problem is right, you'd want different RewriteBase settings for different directories.

It has to be placed in either a .htaccess file in the directory in question, or inside a <Directory...> directive in httpd.conf which applies to the directory in question. ______________________________________________________________________
TANSTAAFL!
 
Hi,

Thought you might have solved it... but it didn't work.

Also checked, the docs and it seemed to indicate that RewriteRule could almost go anywhere... I am still a bit unsure of where it should go though.

Here is some more of the rewrite log. It looks like the rewrite rule works, and rewrote the URI from /somepath/manual/ to /manual/ which (to me) looks fine. If you type in localhost/manual/ in the browser it works, but /manual/ in the config file doesn't seem to work.

From the log...
(2) rewrite /somepath/manual/ -> /manual/
(2) local path result: /manual/

Still haven't figured it out. Looks like the rewrite works, so maybe there is something else wrong??

Any help still appreciated.
Regards
Colin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top