简体   繁体   中英

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.

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM