简体   繁体   中英

.htaccess Subfolder Redirect from http:// to www

I'm trying to push my subfolder from using http://example.com/chat to www.example.com/chat. I've tried the following in my subfolder's .htaccess file with no luck. It does not push the page to a www.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?/$1 

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(subfolder(?:/.*)?)$ http://www.%{HTTP_HOST}/$1 [R=301,L,NE]

Any help would be great.

You can use this in /subfolder/.htaccess :

RewriteEngine On
RewriteBase /subfolder/

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?/$1 [L,QSA]

ie keep redirect rule before internal routing one and simplify your regex.

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