Anonimista
Anonimista

Reputation: 752

htaccess redirect all files in the root directory to coresponding pages in subdirectory

I have several pages in

http://localhost/template

like home.php, about.php, contact.php

In http://localhost/template/sr I have the pages with the same name.

This is what I have in my root .htaccess file

RewriteEngine on
RedirectMatch 301 ^/$ http://localhost/template/sr/

My error.log file reports:

[localhost/sid#923dd8][rid#dd70b0/initial] [perdir C:/xampp/htdocs/template/] pass through C:/xampp/htdocs/template/
[localhost/sid#923dd8][rid#ddd0c8/subreq] [perdir C:/xampp/htdocs/template/] pass through C:/xampp/htdocs/template/index.php
[localhost/sid#923dd8][rid#ddb0c0/initial] [perdir C:/xampp/htdocs/template/] pass through C:/xampp/htdocs/template/
[localhost/sid#923dd8][rid#ddd0c8/subreq] [perdir C:/xampp/htdocs/template/] pass through C:/xampp/htdocs/template/index.php

This setup doesn't redirect I keep getting the pages from the root directory.

Upvotes: 3

Views: 1346

Answers (1)

anubhava
anubhava

Reputation: 785128

If you're trying to redirect pages to coresponding pages in subdirectory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^([^/]+)/?$ /template/sr/$1 [L]

Upvotes: 4

Related Questions