This is my /etc/apache2/sites-availables/mysite.com file configuration
ServerAdmin LOLILOL#LOL.com
ServerName www.example.com
Redirect permanent / http://www.example.com/
ServerAlias example.com
DocumentRoot /home/example/www
SuexecUserGroup example example
<Directory />
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order deny,allow
Allow from all
</Directory>
<Directory /home/example/www>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Please can Someone tell my where to find the issue to redirect non www to www ?
PS : I can't acces to my site from http://example.com (Only from http://www.example.com/)
HELP ME PLEASE !!!!
I do it in the .htaccess.
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
Related
I have a website built based on PHP/HTML/CSS and which follow the MVC design pattern.
The website is the following : https://admin.site.com
It works well on Localhost. However, when I upload it to my apache2 server, I encounter a problem. It seems that the "/" get removed automatically after ".com" . As I need to be authentificated to access the website, I'm directly redirected to the login page but as the "/" has been removed, it is not working.
I get https://admin.site.comlogin/ instead of https://admin.site.com/login/
Before posting here, I tried to check everything but I run out of ideas.
Especially the fact that this same website works on a different subdomain that I initiated for testing : http://sub1.site.com
The only difference is that that this one does not have any SSL certificate but I don't know it's something that may cause the problem.
Here my different files in Apache2 server.
000-defaut.conf
<VirtualHost *:80>
ServerAdmin contact#site.com
ServerName site.com
ServerAlias sub1.site.com
DocumentRoot /var/www/sub1/interface/
<Directory /var/www/sub1/interface/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin contact#site.com
ServerName site.com
ServerAlias admin.site.com
Redirect permanent "/" "https://admin.site.com"
DocumentRoot /var/www/site/interface/
<Directory /var/www/site/interface/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
defaut-ssl.conf
ServerAdmin contact#site.com
ServerName site.com
ServerAlias admin.site.com
DocumentRoot /var/www/site/interface/
<Directory /var/www/site/interface/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
...
</VirtualHost>
.htaccess
`# Remove the question mark from the request but maintain the query string
RewriteEngine On
# Uncomment the following line if your public folder isn't the web server's root
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?$1 [L,R]
Do you have any insight about why it is not working and the slash get removed ?
I solved my issue simply :
I have added a trailing slash at the end to the redirect permanent directive.
Redirect permanent "/" "https://admin.site.com/"
I had some conflict as well with some directive. So I removed all the Directory directive to my conf file and let them only on my apache2.conf .
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Hello i have a site on my own computer hosting. I setup wordpress and apache on it. Got a domain name and registered it on cloudflare. They also offer a free certificate which i got and put into folder .crt and .key files. Here is my configuration for ssl and non-ssl for apache
HTTPS
<VirtualHost *:443>
ServerName hascelin.fun
ServerAdmin hascelin#gmail.com
DocumentRoot /var/www/html/hascelin.fun/
ServerAlias www.hascelin.fun
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html/hascelin.fun/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
#RewriteEngine on
#RewriteCond %{SERVER_NAME} =www.hascelin.fun [OR]
#RewriteCond %{SERVER_NAME} =hascelin.fun
#RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
SSLEngine on
SSLCertificateFile /home/orest/cert/hascelin.crt
SSLCertificateKeyFile /home/orest/cert/hascelin.key
</VirtualHost>
HTTP
<VirtualHost *:80>
ServerName hascelin.fun
ServerAdmin hascelin#gmail.com
DocumentRoot /var/www/html/hascelin.fun/
ServerAlias www.hascelin.fun
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html/hascelin.fun/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
#RewriteEngine on
#RewriteCond %{SERVER_NAME} =www.hascelin.fun [OR]
#RewriteCond %{SERVER_NAME} =hascelin.fun
#RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
#SSLEngine on
#SSLCertificateFile /home/orest/cert/hascelin.crt
#SSLCertificateKeyFile /home/orest/cert/hascelin.key
Media files are loading from http
I am having an issue with getting Laravel to work properly with Apache2. This is my config file, but whenever it go to my domain I see directory list, and I need to enter to portfolio/public to see the app. That's also what the url become (my-website.com/portfolio/public/).
Is there any way I can fix this?
I've been trying to deploy this app for 3 days and still had no success...
Great Thanks!
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName my-domain.com
ServerAlias www.my-domain.com
DocumentRoot /var/www/html/portfolio/public
<Directory /var/www/html/portfolio/public>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<Directory /var/www/html/portfolio/public>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory /usr/lib/cgi-bin>
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
This might help you
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public/index.php/$1 [L]
Source
Possible Duplicate
I did the same. But instead of using .htaccess I put these lines
RewriteEngine On
RewriteCond %{HTTP_HOST} ^one\.domain\.com
RewriteRule ^(.*)$ /folder/$1 [R=301]
to /etc/apache2/sites-available/default.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All // I even changed None to All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All // I even changed None to All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine On
RewriteCond %{HTTP_HOST} ^one\.domain\.com
RewriteRule ^(.*)$ /folder/$1 [R=301]
</VirtualHost>
After restarting apache2, When I browse one.domain.com , Mozzila, IE Chrome not responding, But safari gives error
Since it's a 301 you're telling the browser to redirect to one.domain.com/folder which still passes your host condition. Meaning on redirect 2 you're on page one.domain.com/folder/folder
I'm trying to rewrite /test to /test.php. If I go to the link directly it will give me the php page that works but when I go to /test it just gives a 404 not found error. I have enabled mod_rewrite and given the /var/www 755 permissions.
.htaccess
RewriteEngine On
RewriteRule ^test test.php [NC]
test.com.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName test.com
ServerAlias www.test.com
DocumentRoot /var/www/test.com
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/test.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
FIXED: Changed FollowSymLinks to +FollowSymLinks
If you use RewriteLogLevel you will see what the server does. In your case, you will see a applying pattern '^test' to uri '/test'. Update your rule to :
RewriteRule ^/test$ /test.php [NC]