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 question, redirect everything from certain sub dir
Author
Conz



Joined: 28 Jan 2016
Posts: 1
Location: Netherlands

PostPosted: Thu 28 Jan '16 18:57    Post subject: Rewrite question, redirect everything from certain sub dir Reply with quote

An issue was thrown my way that I'm trying to resolve with php and Apache.
I have a server where I want to redirect everything from a certain sub directory to a single php script.
This would have to include sub directories in that directory that do not actually exist on disk, I can then pick up the request uri in php and do stuff with that.

As example:
http://server.example.com/mydir/my/sub/stuff/file.txt should load /mydir/whatever.php
But if the my/sub/stuff/file.txt directories and file do not actually exist on the server.
The sub directories will also be dynamic so I can't really hard code anything. The only fixed given thing is that it's all under /mydir. The php file does not have to be under there if that would create issues with the rewrite rules either.

I can rewrite a single file in the same folder but anything more advanced and it becomes voodoo for me.

The server is Fedora 22 with Apache 2.4.17-1
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Thu 04 Feb '16 17:11    Post subject: Reply with quote

You can use a <Location> container and within that
Code:

<Location /mydir/>
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1
<Location>
Back to top


Reply to topic   Topic: Rewrite question, redirect everything from certain sub dir View previous topic :: View next topic
Post new topic   Forum Index -> Apache