drakenation
drakenation

Reputation: 195

Redirect all requests to a directory and it's subdirectories to a file inside the directory, using Apache2 server

The Document folders are structured like this

/var/wwww/ (root)
    java/
    ...
    php/
        projectone/
            controller/
            view/
                index.php
            ...
        projecttwo/
            ...

I want all requests to /php/projectone or it's subfolders to redirect to /php/projectone/view/index.php, while requests to /php/projecttwo and other folders should not be redirected.

I believe using mod_rewrite is the way, however, I still haven't achieved what I want.

Upvotes: 0

Views: 1011

Answers (1)

Prix
Prix

Reputation: 19528

Place an .htaccess inside project one folder with the following rule:

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /php/projectone/

RewriteRule ^(view/)?index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . view/index.php [L]

And you can repeat that for any other project folders you have. by changing the RewriteBase.

Upvotes: 1

Related Questions