I have an .htaccess file see below
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
#Every www request to non-www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]
#every http request in amdinistrator folder redirect to https
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/administrator
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
#every https request except ftp and one specific request redirect to http
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !^/ftp
RewriteCond %{REQUEST_URI} !=/preview/index.php?request_type=preview_engime
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301]
#redirect which request contains PUBLIC_AJAX_ENGIME
RewriteRule ^(.*)PUBLIC_AJAX_ENGIME(.*)$ index.php?request_type=ajax_engime [L]
#files and directories
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
</IfModule>
I do not want redirection in this case:
https://somewebsite.domain/preview/index.php?request_type=preview_engime
but the system redirects here
http://somewebsite.domain/index.php?request_type=preview_engime
and I do not understand why.
Thank you!
FF
This is because your url contains a querystring. You cant match against QueryString using REQUEST_URI variable. You need to match against THE_REQUEST variable. Replace your RewriteCond with this :
RewriteCond %{THE_REQUEST} !/index\.php\?request_type=preview_engime [NC]
Related
I have multiple domains that point to the same folder on my server. The code in index.php page recognizes which domain is accessing it and shows different content for each domain.
Now I want that www.domain-a.com\sitemap.xml opens /sitemap-a.xml so that each domain has its own sitemap.
I use the following rule in my .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*domain-a\.com$
RewriteRule ^sitemap.xml$ sitemap-a.xml [NC]
However, if I access www.domain-a.com\sitemap.xml then the content from the file /sitemap.xml is shown instead of the file sitemap-a.xml.
Is the redirecting rule wrong? If so, how can I fix it?
I am using Laravel. This is the full .htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*domain-a\.com$
RewriteRule ^sitemap.xml$ sitemap-a.xml [NC]
# browser request: .php to non-php
# https://stackoverflow.com/questions/13222850/redirect-php-urls-to-urls-without-extension
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Can you try this rule just above # Handle Authorization Header line:
RewriteCond %{HTTP_HOST} (?:^|\.)domain-a\.com$ [NC]
RewriteRule ^sitemap\.xml$ /sitemap-a.xml [L,NC]
Currently, this is my .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Redirect to HTTPS
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule !/status https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php?p=$1 [QSA,L]
# Custom Redirects
Redirect /investors/reporting/estma /investors/investor-reporting/financial-information#estma
RewriteCond %{HTTP_HOST} ^portal\.arcresources\.com [NC]
RewriteRule ^(.*) https://www\.arcresources\.com/portals [L,R=301]
</IfModule>
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
The redirect works fine if you just type the domain, so arcresources.com properly redirects to https://www.arcresources.com. It also works if you include www and any URI, so www.arcresources.com/investors redirects correctly as well.
The problem is typing just the domain + a URI, so arcresources.com/investors redirects to only https://arcresources.com/investors (no www.), resulting in a connection refusal.
I'm sure I'm missing something simple, but all my attempts so far have either added double "www"s or resulted in too many redirects.
Thanks in advance :)
Try it like this:
RewriteEngine On
RewriteBase /
# Redirect HTTP with www to HTTPS with www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Redirect HTTP without www to HTTPS with www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Redirect HTTPS without www to HTTPS with www
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
#RewriteCond %{REQUEST_URI} !index.php [NC]
RewriteRule (.+) index.php?p=$1 [QSA,L]
I am having a site with ssl. All pages from site are redirecting to https with www.
I want following urls to be non ssl, so it will work with http only.
www.domain.com/admin/order/remote_request?
www.domain.com/admin/order/print/131756
My current htacess file is ad follows
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Redirect non www request to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Redirect http request to https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Try :
# Redirect http request to https
RewriteCond %{THE_REQUEST} !/admin/order/remote_request\? [NC]
RewriteCond %{THE_REQUEST} !/admin/order/print/131756 [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I have the following htaccess file. I do not want to perform a redirect from https to http on a certain file. how can i achieve this?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.spectrumasa.com$ [NC]
RewriteRule ^(.*)$ http://www.spectrumgeo.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^intranet.spectrumasa.com$ [NC]
RewriteRule ^(.*)$ http://www.spectrumgeo.com/ [R=302,L]
RewriteCond %{HTTP_HOST} ^www.asb.com.au$ [NC]
RewriteRule ^(.*)$ http://www.spectrumgeo.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.spectrum-geopex\.com\.eg$ [NC]
RewriteRule ^(.*)$ http://www.spectrumgeo.com/spectrum-geopex [R=301,L]
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/server-status
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I would like to access only the following through https http://www.spectrumgeo.com/wp-content/uploads/Spectrum_logo_email-171w.jpg
Add a condition to your rule:
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/wp-content/uploads/Spectrum_logo_email-171w\.jpg$
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
You can have something complex in picking with to redirect to https:// from http:// but you can accomplish a simple redirect on a single file via this method.
RewriteEngine
Redirect http://www.spectrumgeo.com/wp-content/uploads/Spectrum_logo_email-171w.jpg https://www.spectrumgeo.com/wp-content/uploads/Spectrum_logo_email-171w.jpg
This will solve accessing only the above url you have through https://
I would like to have the folder https_folder (including all subfolders and files) forcing https, but every other directory or file, utilizing http.
Folder structure:
foldera
folderb
https_folder
folderc
I tried to set it as followed, however i dont seem to get it working
redirect for http /https_folder
RewriteCond %{SERVER_PORT} = 80
RewriteRule ^https_folder/?$ https://%{HTTP_HOST}%/httpd_folder [R=301,QSA,L,NE]
redirect for https non /market pages
RewriteCond %{SERVER_PORT} =443
RewriteCond %{REQUEST_URI} !^/https_folder [NC]
RewriteRule ^/?(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
Any help would be appreciated
Do this:
RewriteCond %{REQUEST_URI} /https_folder/? [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(https_folder)(/.*)?$ https://%{HTTP_HOST}/$1$2 [R=301,L,NE]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !/https_folder/? [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L,NE]
Put this code in your .htaccess file:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
# redirect to https if URI has https_folder
RewriteCond %{HTTPS} off
RewriteRule ^https_folder/? https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]
# redirect to https if URI doesn't have https_folder
RewriteCond %{HTTPS} on
RewriteRule ^(?!https_folder/?)(.*)$ http://%{HTTP_HOST}/$1 [R=301,L,NC]