I am trying to setup an apache2 redirect from https://www.dolgins.com to https://dolgins.com and cannot get it working correctly. I followed this guide and have the A records pointed correctly.
Here is a screenshot of my apache config
Here is my .htacess file located in the DocumentRoot folder:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
Any ideas? Also, I want the URL to change. What would I need to do?
Thank you
Joseph
Related
I set up prerender.io for CRA and it works well, but when bot hits URL without parameters it puts in the end of URL - string ".var"
I tried variations of (.*) but it seems not working. Any ideas?
Here is .htaccess file
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
<IfModule mod_headers.c>
RequestHeader set X-Prerender-Token "TOKEN"
RequestHeader set X-Prerender-Version "prerender-apache#2.0.0"
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
<IfModule mod_proxy_http.c>
RewriteCond %{HTTP_USER_AGENT} googlebot|bingbot|yandex|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest\/0\.|pinterestbot|slackbot|vkShare|W3C_Validator|whatsapp [NC,OR]
RewriteCond %{QUERY_STRING} _escaped_fragment_
RewriteCond %{REQUEST_URI} ^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.gif|\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.dat|\.dmg|\.iso|\.flv|\.m4v|\.torrent|\.ttf|\.woff|\.svg))
RewriteRule ^(index\.html|index\.php)?(.*) https://service.prerender.io/%{REQUEST_SCHEME}://%{HTTP_HOST}/$2 [P,END]
</IfModule>
</IfModule>
Lately #MrWhite gave us another, better and simple solution - just add DirectoryIndex index.html to .htaccess file will do the same.
From the beginning I wrote that DirectoryIndex is working but NO!
It seems it's working when you try prerender.io, but in reality it was showing website like this:
and I had to remove it.
So it was not issue with .htaccess file, it was coming from the server.
What I did was I went into WHM->Apache Configurations->DirectoryIndex Priority and I saw this list
and yes that was it!
To fix I just moved index.html to the very top second comes index.html.var and after rest of them.
I don't know what index.html.var is for, but I did not risk just to remove it. Hope it helps someone who struggled as me.
When I deploy my website built with React and React-router the landing page of my website works fine but when I try to navigate into my website I run into 403 forbidden response. I use Apache as an HTTP server and the general config of my server is the following :
<IfModule mod_php.c>
php_value date.timezone Europe/Brussels
</IfModule>
<IfModule mod_userdir.c>
UserDir /var/www/users/staff/*
</IfModule>
For your information, the website is located under /var/www/projects
I added the following .htaccess to my project :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>
Despite those configurations the 403 forbidden error when navigating in pages managed by react-router. Did I miss some configurations?
It seems that the settings you have applied are not enough, You should change some parameters in apache.conf too...
open the apache main config file, Its path varies depending on your distribution, that's located in one of these locations:
1- /etc/apache2/httpd.conf
2- /etc/apache2/apache2.conf
3- /etc/httpd/httpd.conf
4- /etc/httpd/conf/httpd.conf
look for "AllowOverride" parameter like the example below:
<Directory "/var/www/blahblah">
AllowOverride All
</Directory>
And give the "All" value to that.
Then create a .htaccess file in the root folder of the webserver & set the following configs:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
NOTE: Before performing these things you have to enable the rewrite module, By entering the following commands you can do this:
debian base: sudo a2enmod rewrite
centos: uncomment mod_rewrite.so in /etc/httpd/conf/httpd.conf
Finally, restart your web server... Now expected there is no anymore problem.
If you got any permission/server error take a look at the webserver logs which are located in one of these locations:
1- /var/log/httpd/
2- /var/log/apache2
I need to make some changes on an existing CakePHP project, but I can't run it on localhost because every time I try to access http://localhost:8080/{name-of-project}/ it redirects me to http://www.{name-of-project}.com.
Any help would be appreciated.
I also encountered this one when Im still using cakephp2 and still duable using cakephp3
from live .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$ [NC]
RewriteCond %{HTTPS}s ^on(s)|off
RewriteRule ^(.*)$ http%1://www.mydomain.com/$1 [R=301,QSA,L]
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
I change it to this one
.htaccess local
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Most likely in your .htaccess file there is a non-www to www redirect installed.
As Adam notes, it may be useful to clear your browser cache when working with redirects. A cached redirect would no longer hit your server configuration so any changes you do will not be visible.
I am facing issue in my first intallation of CakePHP.
I am working on Windows OS and using WAMP. I am able to point my browser to localhost -> phpcake to open my installation of CakePHP.
However I get an error as below:
Missing Controller
Error: PhpcakeController could not be found.
Following are the steps which I followed for installing CakePHP:
Unzipped CakePHP, version 2.4.7 and loaded that in my WAMP
Created database using phpMyAdmin
Updated the app\Config\database.php file with login, password and databasename
The contents of the .htaccess files of cake is as below:
phpcake/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
phpcake/app/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
phpcake/app/webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase D:/Vivek/phpcake/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/(app/webroot/)?(img|css|js)/(.*)$
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
The mod_rewrite is disabled on my Apache. If I enable it, then I get 404 error on launching CakePHP install.
Could you guide me as to which step am I missing?
Finally i got it working. This is what i was doing (wrong).
In my WAMP i created an alias directory. Apache -> Alias -> Add an Alias Directory. In this alias i pointed to the location of my CakePHP unzipped folder. I updated the App/Config/Database.php to point to created MySQL database. However on selecting mod_rewrite module in Apache i was getting 404/403 errors. And without mod_rewrite i was getting missing controller error.
Missing Controller
Error: PhpcakeController could not be found.
I tried fresh installations 3 times with same results.
My understanding is that the mod_rewrite, the instructions in Alias file and .htaccess files were creating this trouble.
So this is what i did (Worked):
I copied my CakePHP into WAMP's www directory. That's it, it did the trick. I went through various articles about .htaccess, and mod_rewrite. Frankly speaking it is complex for me.
I have one domain on godaddy (www.mydomain.com). I have placed my cakephp application on this domain. It is working fine for me.
But i have created a subdomain blog.mydomain.com for this godaddy has created a directory named blog inside the www.mydomain.com now how can i redirect the request coming for blog.mydomain.com to the blog/ folder.
I am trying this,
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog.mydomain.com$
RewriteRule ^(.*)$ blog/$1 [L]
RewriteCond %{HTTP_HOST} ^mydomain.com/$
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
It works for single Rewrite condition like,
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog.mydomain.com$
RewriteRule ^(.*)$ blog/$1 [L]
But when i add another rewrite condition for my cake app it shows 500 Internal server error for blog.mydomain.com
Please help me out .............
Put the blog folder in webroot (under your cake directory) and it should work just fine. Or did you need to do something else more fancy?
Try this: http://digitalmemo.neobie.net/2011/04/19/cakephp-bypassing-for-subdomain/
It use to make all the subdomains to be working correctly instead of defining each of the subdomain.