I have this in my .htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L=301]
RewriteCond %{HTTP_HOST} ^www\.clipboards\.com [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L=301]
These condition are working fine with one exception.
If I come from http (non-ssl) it will add index.php?route to my url before sending it to https. This is not the case if I come directly from https in which case it works fine. Can someone help me with this. thanks
You should put your redirects at the top and you can combine the bottom 2 rules. Also note that you have invalid syntax [R,L=301], it should be [R=301,L]
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
Related
I'm using yii2 advanced template for landkrone.com, and I want it to automatically redirect to https by editing htaccess. But after I edit it, it become inaccessible.
This site can’t be reached
landkrone.com took too long to respond.
This is my htaccess:
Options +FollowSymlinks
RewriteEngine On
# deal with backend first
RewriteCond %{REQUEST_URI} /(backend)
RewriteRule ^backend/assets/(.*)$ backend/web/assets/$1 [L]
RewriteRule ^backend/css/(.*)$ backend/web/css/$1 [L]
RewriteRule ^backend/font/(.*)$ backend/web/font/$1 [L]
RewriteRule ^backend/plugins/(.*)$ backend/web/plugins/$1 [L]
RewriteRule ^backend/images/(.*)$ backend/web/images/$1 [L]
RewriteRule ^backend/js/(.*)$ backend/web/js/$1 [L]
RewriteCond %{REQUEST_URI} !/backend/web/(assets|css|font|plugins|images|js)/
RewriteCond %{REQUEST_URI} /(backend)
RewriteRule ^.*$ backend/web/index.php [L]
RewriteCond %{REQUEST_URI} /(assets|css|js|img|fonts|uploads)
RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L]
RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]
RewriteRule ^js/(.*)$ frontend/web/js/$1 [L]
RewriteRule ^img/(.*)$ frontend/web/img/$1 [L]
RewriteRule ^fonts/(.*)$ frontend/web/fonts/$1 [L]
#RewriteRule ^uploads/(.*)$ frontend/web/uploads/$1 [L]
RewriteRule ^uploads/(.*)$ uploads/$1 [L]
RewriteCond %{REQUEST_URI} !/(frontend|backend)/web/(assets|css|js|img|images|fonts|uploads|plugins|font)/
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ frontend/web/index.php
RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I used this htaccess to my other website in other server and it works fine. Why is this not working? Please help...
Now I am using advance template Yii2. And using htaccess to redirect http:://mydomain.com to frontend/web folder.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/(assets|css|js|ember)
RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L]
RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]
RewriteRule ^js/(.*)$ web/js/$1 [L]
RewriteRule ^ember/(.*)$ web/ember/$1 [L]
RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css|js|ember)/
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ frontend/web/index.php/$1 [L,QSA]
#RewriteRule (.*) frontend/web/$1 [L]
</IfModule>
but when I go to any url ie : http://mydomain.com/abc . the site always point to home page.. Even url not invailable..
Thanks in advance
This .htaccess file works for me, you have to put this .htaccess file under
yii2advance/frontend/ root directory,
so when you access yii2advance.com/frontend/ it'll rewrite as yii2advance.com/frontend/web
RewriteEngine On
RewriteBase /
RewriteRule ^(.*) frontend/web/index.php/$1 [QSA,L,NC]
please create .htaccess in frontend/web with:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/(assets|css|js|ember)
RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L]
RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]
RewriteRule ^js/(.*)$ web/js/$1 [L]
RewriteRule ^ember/(.*)$ web/ember/$1 [L]
RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css|js|ember)/
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ frontend/web/index.php/$1 [L,QSA]
#RewriteRule (.*) frontend/web/$1 [L]
I have the following .htaccess code that tells the server to point certain sub domains to to a sub folder and then also handles the rewriting of the root domains.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
ErrorDocument 404 ./404.php
RewriteCond %{HTTP_HOST} ^secretplace\.testwebsite\.local
RewriteRule ^(.*)$ /secretplace/$1 [P,NC,QSA]
RewriteCond %{HTTP_HOST} ^payment\.testwebsite\.local
RewriteRule ^(.*)$ /payment/$1 [P,NC,QSA]
RewriteCond %{HTTP_HOST} ^login\.testwebsite\.local
RewriteRule ^(.*)$ /login/$1 [P,NC,QSA]
RewriteCond %{HTTP_HOST} ^signup\.testwebsite\.local
RewriteRule ^(.*)$ /signup/$1 [P,NC,QSA]
RewriteCond %{HTTP_HOST} ^fbauth\.testwebsite\.local
RewriteRule ^(.*)$ /fbauth/$1 [P,NC,QSA]
RewriteCond %{HTTP_HOST} ^masterapi\.testwebsite\.local
RewriteRule ^(.*)$ /masterapi/$1 [P,NC,QSA]
RewriteCond %{HTTP_HOST} ^www\.testwebsite\.local$ [NC]
RewriteRule ^(.*)$ http://testwebsite.local/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^testwebsite\.local$ [NC]
RewriteRule ^(.*)$ /account_redirect/$1 [P,NC,QSA]
RewriteCond %{HTTP_HOST} ^testwebsite\.local$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ref_([a-zA-Z0-9-]+)/?$ index.php?ref=$1 [L,QSA]
RewriteRule ^api/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/?$ api.php?function=$1&method=$2&extra=$3 [L,QSA]
RewriteRule ^api/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/?$ api.php?function=$1&method=$2 [L,QSA]
RewriteRule ^api/([a-zA-Z0-9-]+)/?$ api.php?function=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/?$ $1-$2.php [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [L,QSA]
</IfModule>
It works, but on my local apache install the page loading is real sluggish. It takes a few seconds just to switch between pages.
Just so you know the very last line of code allows me to remove the .php extension from pages. So instead of http://testwebsite.local/features.php, it loads http://testwebsite.local/features/.
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [L,QSA]
Is there something obvious in my code that I'm doing wrong? I'm not quite sure how to debug .htaccess.
Why are you using P flag instead of L flag ? This requires mod_proxy and can slow down htaccess execution. Seems to me you don't need it in your case.
If i had to write your code myself, it would look like this
ErrorDocument 404 /404.php
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(secretplace|payment|login|signup|fbauth|masterapi)\. [NC]
RewriteRule ^(.*)$ /%1/$1 [L,NC,QSA]
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^testwebsite\.local$ [NC]
RewriteRule ^(.*)$ /account_redirect/$1 [L,NC,QSA]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
RewriteRule ^ref_([a-zA-Z0-9-]+)/?$ /index.php?ref=$1 [L,QSA]
RewriteRule ^api/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/?$ /api.php?function=$1&method=$2&extra=$3 [L,QSA]
RewriteRule ^api/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/?$ /api.php?function=$1&method=$2 [L,QSA]
RewriteRule ^api/([a-zA-Z0-9-]+)/?$ /api.php?function=$1 [L,QSA]
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/?$ /$1-$2.php [L,QSA]
RewriteCond %{REQUEST_URI} ^/([^/]+)/?$
RewriteRule ^.*$ /%1.php [L,QSA]
Example URL's:-
www.domain.com/index.php?bob
www.domain.com/index.php?jane
www.domain.com/index.php?fred
Need rewriting like:-
www.domain.com/bob
www.domain.com/jane
www.domain.com/fred
Have tried with many variations now but the closest I can get to is:-
www.domain.com/?bob
www.domain.com/?jane
www.domain.com/?fred
The below in .htaccess achieves this...
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]
Please could someone point out what I need to modify to bin the ? (question mark) in the URL?
Edit
Just noticed that since applying the answer given by anubhava below that robots.txt for example doesn't resolve to the .txt file but just displays the homepage.
.htaccess below:-
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+index\.php\?([^\s&]+) [NC]
RewriteRule ^ %1? [R=301,L]
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#pos1
RewriteRule ^([^/]+)/?$ index.php?$1 [L,QSA] <--
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
#pos2
If I add the <-- line in pos1, the robots.txt URL returns a 404 page not found error.
If I add the <-- line in pos2, the robots.txt URL just displays the homepage.
Edit2
In the meantime, I have excluded robots.txt from rewrites by adding the following under Rewrite Base /:-
RewriteRule ^robots.txt - [L]
You can use this code:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+index\.php\?([^\s&]+) [NC]
RewriteRule ^ %1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?$1 [L,QSA]
You can also use this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]
Hi allm i'm having some issues in redirecting the non www pages to the www. pages for my cakephp site.
I've tried
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
but it doesn't seem to work.
My cakephp app resides in a subfolder. eg. www.domain.com/my.
i've added the above code to the root folder, www.domain.com/
any suggestions? thanks?
*update
This my .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^.*$ http://www.domain.com%{REQUEST_URI} [R=301,L]
i'm getting an extra webroot/index.php?url= inserted into the url. Instead of www.domain.com/my/apple, i'm getting www.domain.com/my/webroot/index.php?url=apple
thanks to all once again.
Your code is not quite right. See below.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^.*$ http://www.domain.com%{REQUEST_URI} [R=301,L] # <-- Mind the 'L'!
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
if domain is .co.uk
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.co\.uk$ [NC]
RewriteRule ^.*$ http://www.domain.co.uk%{REQUEST_URI} [R=301,L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app/webroot/$1 [QSA,L]
I have tried the below code below and it worked for me:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^gigsadda\.com$ [NC]
RewriteRule ^.*$ http://www.gigsadda.com%{REQUEST_URI} [R=301,L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>