codeigniter, htaccess force https except one url - php

I try to force all urls to https except one url. so far no success. Anyone knows what is wrong with my htaccess or codeignter?
Url test 1:
http://hub-dev-1.andatech.com.au/utility/mandrills/email_bounced_back
Should stays as
http://hub-dev-1.andatech.com.au/utility/mandrills/email_bounced_back
Url test 2:
http://hub-dev-1.andatech.com.au/controller/method
I use this tool to test htaccess: http://htaccess.mwl.be/
Here is my htaccess
RewriteOptions inherit
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/utility/mandrills/email_bounced_back
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_URI} !^/(assets|test)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php/$1 [PT,L]
Header set Access-Control-Allow-Origin "*"
Test on http://htaccess.mwl.be, working.
Test on browser,
http://hub-dev-1.andatech.com.au/utility/mandrills/email_bounced_back redirects to
https://hub-dev-1.andatech.com.au/utility/mandrills/email_bounced_back
apache conf:
<VirtualHost *:80>
ServerAdmin test#test.com
ServerName hub-dev-1.andatech.com.au
ServerAlias www.hub-dev-1.andatech.com.au
DocumentRoot /home/thehub/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/thehub/public_html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
# Hak apache 2.2
# Order deny,allow
Allow from all
# Hak apache 2.4
Require all granted
</Directory>
</VirtualHost>
ssl apache conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin test#test.com
ServerName hub-dev-1.andatech.com.au
ServerAlias www.hub-dev-1.andatech.com.au
DocumentRoot /home/thehub/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/thehub/public_html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
# Hak apache 2.2
# Order deny,allow
Allow from all
# Hak apache 2.4
Require all granted
</Directory>
SSLCertificateFile /etc/letsencrypt/live/hub-dev-1.andatech.com.au/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hub-dev-1.andatech.com.au/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

Related

What causing this error proxy_fcgi:error] AH01071: Got error 'Primary script unknown'

I'm getting the proxy_fcgi:error] AH01071: Got error 'Primary script unknown' error very frequently. Can anyone tell me what causing this error. What I learned so far is Rewrite rule may cause this issue. But do not understand exactly what causing this issue. Following are my Rewrite rules:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory /var/www/>
Options -Indexes +FollowSymLinks -MultiViews
AllowOverride None
Require all granted
# Setting rewrite rules
RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
# Show 404 error if there is any slash after page name
RewriteRule ^.+?\.(php|html?)/ - [L,R=404,NC]
# Custom Directory Index Files
DirectoryIndex index.php index.html
</Directory>
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory /var/www/>
Options -Indexes +FollowSymLinks -MultiViews
AllowOverride None
Require all granted
# Setting rewrite rules
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
# Show 404 error if there is any slash after page name
RewriteRule ^.+?\.(php|html?)/ - [L,R=404,NC]
# Custom Directory Index Files
DirectoryIndex index.php index.html
</Directory>
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
</VirtualHost>
</IfModule>

Wordpress Permalinks 404 error with HTTPS host

My new permalinks continue displaying a 404 error on my site even after adding the AllowOverride and Rewrite modules parameters. Here is my default-ssl.conf file :
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin vincent.zzz#gmail.com
DocumentRoot /var/www/zzz
ServerName zzz.com.vn
ServerAlias www.zzz.com.vn
<Directory "/var/www/zzz">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
<Location />
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
</Location>
#end of custon stuff.....
And here is the normal http part of my apache2.conf file :
<VirtualHost *:80>
ServerName zzz.com.vn
DocumentRoot /var/www/zzz
<Directory "/var/www/zzz">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
DirectoryIndex index.php
#force SSL
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=permanent]
</Directory>
Would anyone have an idea ?
Are you sure that mod_rewrite is enabled? Is there a symbolic link to rewrite.load in /etc/apache2/mods-enabled?
You can enable the mod with:
sudo a2enmod rewrite

Laravel5 Ubuntu only working when myvirtualdomain/index.php/subsites

I'm using Ubuntu 14.04. I have installed LAMP, Composer and I installed Laravel. I created virtual domain (laravel.dev) and it works, but only when I'm using for simple laravel.dev/index.php/auth/login. When I use laravel.dev/css I have laravel/public/css folder. I have default .htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
AllowOverride All
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
And my *.conf file:
<VirtualHost *:80>
ServerName laravel.dev
ServerAdmin webmaster#laravel.dev
DocumentRoot /var/www/laravel/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
How can I fix it?
My main page:
http://i.imgur.com/AxQjV9q.png
I fall this problem.I solved it using apache mod rewrite enable.For that follow this
http://www.kingpabel.com/apache-mod_rewrite/
Currently, your virtualhost doesn't allow overriding the rewriting settings in the .htaccess of your project.
You should add the following lines to your .conf file, in the virtualhost :
<Directory "/var/www/laravel/public">
AllowOverride All
</Directory>
Which would result in the following file :
<VirtualHost *:80>
ServerName laravel.dev
ServerAdmin webmaster#laravel.dev
DocumentRoot /var/www/laravel/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/laravel/public">
AllowOverride All
</Directory>
</VirtualHost>

Xampp Virtual Host for sub directory

Question
I would like to map
www.mydomain.com/some/url
to
C:/xampp/htdocs/some/dir
What I've got
Xampp
Wordpress
htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /some/path/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /some/path/index.php [L]
</IfModule>
Hosts file
127.0.0.1 www.mydomain.com
httpd-vhosts.conf (included in httpd.conf)
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/someDir/"
ServerName mydomain.com/some/path
</VirtualHost>
additional info (httpd.conf)
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
Current Outcome
500 Internal Server Error error log shows
Request exceeded the limit of 10 internal redirects due to probable configuration error.
Add the alias to your httpd.conf
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
Alias /some/url C:/xampp/htdocs/some/dir

Apache's Alias directive is not working as expected

I am trying to integrate my portal with my website.
My website :
http://example.com
and My portal :
http://portal.com
Now I want to see my portal from :
http://example.com/portal
Part of my core apache config file (sites-enabled/website):
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName example.com
DocumentRoot /home/example/WebSite2.0/WebContent
DirectoryIndex index.php index.html
<Directory /home/example/WebSite2.0/WebContent>
Options +IncludesNOEXEC
AllowOverride None
Order allow,deny
allow from all
XBitHack On
AddType text/html .html
AddHandler server-parsed .html
</Directory>
Alias /portal /home/example/portal/CodeIgniter_2.1.0
<Directory /home/example/portal/CodeIgniter_2.1.0>
DirectoryIndex "index.php"
allow from all
Options +Indexes
#Options FollowSymLinks MultiViews
Order allow,deny
RewriteEngine On
RewriteBase /portal
#RewriteRule ^test\.html$ test.php
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond $1 ^(css|images|js)
RewriteRule ^(.*)$ $1
</Directory>
</VirtualHost>
As you see my portal functions on top of CodeIgniter; Hence -
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Part of my core apache config file (sites-enabled/portal) :
<VirtualHost *:443>
ServerAdmin webmaster#localhost
ServerName portal.com
ServerAlias www.portal.com
DocumentRoot /home/example/portal/CodeIgniter_2.1.0
DirectoryIndex "index.php"
SSLEngine On
SSLCertificateFile "ssl/portal.com.crt"
SSLCertificateKeyFile "ssl/portal.com.key"
<Directory /home/example/portal/CodeIgniter_2.1.0>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Header unset Server
ServerSignature Off
</Directory>
</VirtualHost>
Now the real problem is when I open http://example.com/portal the browser is looking for the images in the DocumentRoot and not in Alias.
e.g. for image from portal,
<img src="/images/example.png" style="margin-left:30px;height:50px;">
apache error log says -
File does not exist: /home/example/WebSite2.0/WebContent/images/example.png
I would hate to make changes to my code. I just want to get this thing working from the apache config file itself. Please help me do this.
RewriteBase /portal require that the url should begin with /portal. So:
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
will not be hit.
<img src="/images/example.png" style="margin-left:30px;height:50px;">
will try to search file from DocumentRoot.
update1
For there is RewriteBase /portal, example.com/portal/images will hit the Rewrite rule, but example.com/images will not, so:
<img src="/images/example.png" style="margin-left:30px;height:50px;">
should be:
<img src="/portal/images/example.png" style="margin-left:30px;height:50px;">
update2
It is the answer given by #Hussain Tamboli himself, with:
RewriteRule /(images|js|css)/(.+)\.(.+)$ /portal/$1/$2.$3 [PT].
/images/Invoice.png will rewrite to /portal/images/Invoice.png

Categories