简体   繁体   中英

Rewrite index.html (default) but not index.php .htaccess

I didn't quite find what I need despite I'm sure it is asked before..

I need to rewrite index.html to a subdirectory but allow index.php to be visited. I have a Wordpress installe in the root, but as long it is in dev I would like it to be visited if addressed directly with exact path and all visitors writing the domain only to be redirected. Thought and tried todo this with .htaccess

Redirect /index.html http://www.example.com/home

But this redirects also index.php to the subdirectory. I also tried adding

remove_filter('template_redirect', 'redirect_canonical'); 

To the functions.php

What next?

Put the following code at root .htaccess file :

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/home/
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*)       /home/$1 [L,R=302]

the above code will redirect any request to /home/ directory including main domain and excluded only the index.php

for example if request site.com/page it will go to site.com/home/page

if you request site.com it will direct you to site.com/home/

but if you request site.com/index.php it will go to site.com/index.php

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