logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Rewrite Rule Help
Author
jasch



Joined: 11 Apr 2008
Posts: 7

PostPosted: Thu 04 Jun '09 22:41    Post subject: Rewrite Rule Help Reply with quote

I am having a hard time, creating a rule to forward a directory.

For example, I have

http://www.domain.com/ftp/marte

But I want users to be able to access it as:

http://www.domain.com/marte

as well (without the /ftp subdirectory).

First of, I tried:

RewriteRule ^marte(.*) /ftp/marte/$1

This worked fine for weeks, until I realized anything that started with "marte" was redirected.

So www.domain.com/marte.swf would return a 404 error (apache was looking for it as /ftp/marte.swf

So I changed it to:

RewriteRule ^marte/(.*) /ftp/marte/$1

This worked fine, but it only works when I enter

http://www.domain.com/marte/

If I enter the URL without the slash at the end:

http://www.domain.com/marte

It doesn work.

Any ideas how can I rewrite the rule, so it would work as expected?

Thanks
Back to top
Brian White



Joined: 24 Aug 2008
Posts: 21

PostPosted: Sat 06 Jun '09 10:57    Post subject: Use RewriteCond To Do What You Want Reply with quote

The easiest thing would be to tell Apache not to forward existing directories or files. For example:

Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^marte(.*) /ftp/marte/$1


The first line says only for files that do not exist, the second line says only for directors that do not exist and the third line is the rule that almost does what you want by itself.
Back to top
jasch



Joined: 11 Apr 2008
Posts: 7

PostPosted: Thu 18 Jun '09 17:35    Post subject: Reply with quote

Thanks Brian. It worked perfectly. Too bad if you have multiple entries, you have to repeat the same RewriteCond for every line...
Back to top


Reply to topic   Topic: Rewrite Rule Help View previous topic :: View next topic
Post new topic   Forum Index -> Apache