Hi I have problem with my htaccess. I have new version of website (located at www.mywebsite.cz) and old version (located at mywebsite.cz (without www)).
I need to redirect all non-www pages to www except folder admin which always has to be non-www. Example:
mywebsite.cz/admin/ -> mywebsite.cz/admin/
www.mywebsite.cz/admin/ -> mywebsite.cz/admin/
I have these two htaccess files, one for new website and one for older.
Old website htaccess:
Options +FollowSymLinks
Options -Indexes
RewriteEngine On
#RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{REQUEST_URI} !^/admin/ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
New website htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{REQUEST_URI} ^/admin/ [NC]
RewriteRule ^(.*)$ http://mywebsite.cz/admin/ [R=301,L]
RewriteRule /\.|^\. - [F]
# front controller
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(pdf|js|ico|gif|jpg|png|css|rar|zip|tar\.gz)$ index.php [L]
Problem is when i try www.mybsite.cz/admin/ it returns too many redirects. Can somebody help me please?
Add this as the first rule in your new website's htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ - [L]
Alternatively, exclude /admin
from your front controller rule as
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/admin(/.*)? [NC]
RewriteRule !\.(pdf|js|ico|gif|jpg|png|css|rar|zip|tar\.gz)$ index.php [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.