Apache 2.3 don't rewrite the https traffic,
this is my htaccess
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^example.it$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.it$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$ [OR]
RewriteCond %{HTTP_HOST} ^example.org$
RewriteRule ^(.*)$ https://www.example.org%{REQUEST_URI} [R=301,L]
and this is mi example.conf in site-aviable
AccessFileName .htaccess
<Directory /www/example.org/>
Options FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
But not work for httpS!!
Only http traffic is rewrite
I want if you write https:// or http:// or without http(s) everything is redirected on https://www.example.org
How to do?
Best regards
Related
I have an .htacess on the root of my domain to redirect all traffic to index.php
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
#redirect http to https, remove www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#remove index.php from link
RewriteRule ^index.php$ - [L]
#redirect to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
#remove direct access to all *.php except index.php
<Files *.php>
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Files>
<Files index.php>
Order Allow,Deny
Allow from all
</Files>
Everything works as expected, traffic is redirect, when files exists show file.
now i have an admin folder /admin/ with and index.php and api.php
i can open the /admin/ and /admin/index.php but the /admin/api.php redirects to /index.php
i tried to put an .htaccess inside the /admin/ like this:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine Off
RewriteEngine On
#redirect http to https, remove www
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>
but getting the same results. /admin/ opens, but /admin/api.php redirects to index
found the problem/solution.
needed to add to the .htaccess inside the /admin/
<Files *>
Order Allow,Deny
Allow from all
</Files>
I have set in my Apache config to allow mod_rewrite:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
AllowOverride All
</Directory>
$ sudo a2enmod rewrite
$ service apache2 restart
But why my URLs with .html won't work? eg:
mysite.com/about.html
mysite.com/contact.html
but it works with:
mysite.com/about
mysite.com/contact
How can I have URLs with .html working as well?
EDIT:
This is the .htaccess (modx):
# For full documentation and other suggested options, please see
# http://rtfm.modx.com/evolution/1.0/administration/friendly-url-solutions
# including for unexpected logouts in multi-server/cloud environments
# and especially for the first three commented out rules
#php_flag register_globals Off
AddDefaultCharset utf-8
#php_value date.timezone Europe/Moscow
#Options +FollowSymlinks
RewriteEngine On
RewriteBase /
# Fix Apache internal dummy connections from breaking [(site_url)] cache
RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC]
RewriteRule .* - [F,L]
# Rewrite domain.com -> www.domain.com -- used with SEO Strict URLs plugin
#RewriteCond %{HTTP_HOST} !^$
#RewriteCond %{HTTP_HOST} !^www\. [NC]
#RewriteCond %{HTTP_HOST} (.+)$
#RewriteRule ^(.*)$ http://www.%1/$1 [R=permanent,L] .
# without www
#RewriteCond %{HTTP_HOST} .
#RewriteCond %{HTTP_HOST} !^example\.com [NC]
#RewriteRule (.*) http://example.com/$1 [R=301,L]
# without www all domains
#RewriteCond %{HTTP_HOST} .
#RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
#RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Exclude /assets and /manager directories and images from rewrite rules
RewriteRule ^(manager|assets)/.*$ - [L]
RewriteRule \.(jpg|jpeg|png|gif|ico)$ - [L]
# For Friendly URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
# Reduce server overhead by enabling output compression if supported.
#php_flag zlib.output_compression On
#php_value zlib.output_compression_level 5
I don't see any rule there saying about having .html...
First thing it doesn't make any sense to have these two opposite meaning directives one after another:
AllowOverride None
AllowOverride All
You just need later part that is:
AllowOverride All
Secondly to support extension-less URLs you just need to enable MultiViews option as:
Options Indexes FollowSymLinks MultiViews
When I enable https on my website, the url rewriting doesn't work ( not found ... )
My htaccess:
# URL Rewrite
<IfModule mod_rewrite.c>
RewriteEngine On
# Full path to your site
#
RewriteBase /
# 301 redirect if missing www.
#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^(.*)$ https://www.% {HTTP_HOST}/$1 [R=301,L]
#RewriteRule ^(static/|ajax\.php) - [F,L,NC]
# 301 redirect if missing trailing slash
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]
# Rules
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?do=/$1
</IfModule>
How can I enable https with url rewriting ?
You have AllowOverride None in <Directory /var/www/> entry which means .htaccess isn't enabled.
To enable .htaccess change that to:
AllowOverride All
And restart Apache server.
You need to uncomment the lines first I think.
I'm trying to implement some htaccess rewrite rules. However in not a pro in htaccess.
I have a subdomain gateway in (as described in: .htaccess and rewrite sub domains)
Now i would like to use SEO friendly URL's. The gateway has some subfolders i.e. email in this case.
http://gateway.example.com/email/Param1/Param2/
This url should be rewritten to http://gateway.example.com/email/index.php?hash=Param1&hash2=Param2.
In the email folder I have created a .htaccess file with the following contents:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.* - [L]
RewriteRule ^/(.*)/(.*)/ index.php?hash=$1&hash2=$2
When requesting the http://gateway.example.com/email/Param1/Param2/ i'm now getting a 404. What is wrong with the rule?
You should do it this way
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?([^/]*)/([^/]*)/ /email/index.php?hash=$1&hash2=$2 [L]
you can try this.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^/([^/]*)/([^/]*)/ index.php?hash=$1&hash2=$2
*you need to configure apache(httpd) to accept UrlRewrite by changing AllowOverride from non to all like this :
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
Hoo-boy I've been struggling with this one all day.
The redirect from the subdomains to the script files with subdomain passed in as a parameter work fine.
When one particular subdomain is actually a real folder (phpmyadmin), I can't seem to make it work, at least not with the previously mentioned rule in place.
Here's my stuff:
<VirtualHost *.domain.com:443>
ServerName *.domain.com
ServerAlias *.domain.com
DocumentRoot /home/domain/web
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.* [NC]
RewriteCond %{HTTP_HOST} ^(phpmyadmin)\.domain\.com
RewriteCond %{REQUEST_URI} !^phpmyadmin
RewriteRule ^(.*)$ /phpmyadmin [L]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com
RewriteRule ^\/script2$ /public/script2.php?param1=%1 [L]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com
RewriteRule ^(.*) /public/script1.php?param1=%1 [L]
<Directory /home/domain/web>
Options -Indexes IncludesNOEXEC FollowSymLinks -MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
SSLEngine on
SSLCertificateFile /home/domain/crt
SSLCertificateKeyFile /home/domain/key
</VirtualHost>
Any ideas?
2 problems with:
RewriteCond %{HTTP_HOST} !^www.* [NC]
RewriteCond %{HTTP_HOST} ^(phpmyadmin)\.domain\.com
RewriteCond %{REQUEST_URI} !^phpmyadmin
RewriteRule ^(.*)$ /phpmyadmin [L]
In your target redirect, you do not change the domain. By just using /phpmyadmin, you're not directing to www.domain.com/phpmyadmin, you're directing to phpmyadmin.domain.com/phpmyadmin, which is likely to cause an infinite redirect loop since it will keep matching the phpmyadmin subdomain each redirect. Use:
RewriteRule ^(.*)$ http://www.domain.com/phpmyadmin [L]
Unlike RewriteRule where the initial / is not used, RewriteCond %{REQUEST_URI} does need the leading slash like so:
RewriteCond %{REQUEST_URI} !^/phpmyadmin
Failing to do so means its not matching the directed /phpmyadmin, leading to another potential self-matching infinite redirect loop.
Also you don't need
RewriteCond %{HTTP_HOST} !^www. [NC]
since your url would never start with www and also start with phpmyadmin. Matching
RewriteCond %{HTTP_HOST} ^(phpmyadmin)\.domain\.com
automatically implies the NOT www match condition is also true