How to fix redirect chain issue using htacces - http-redirect

there is a redirect chain issue on my website, regarding ahref testing tool: http://www.website.com/ ; http://website.com/ ; https://www.website.com/.
https://website.com/ - I use this link.
This code is written in the htaccess file, which probably cause the problem:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Header set Strict-Transport-Security: "max-age=31442830; includeSubDomains; preload"

The htaccess logic above should not cause a redirect unless you have a Cloudflare integration or Proxy that does not pass the secure protocol along to the apache server
if you have WordPress then a redirect can be made internally

Related

bluehost shared ssl redirect with htaccess

I am wanting to add a redirect to my bluehost shared ssl page:
https://secure.bluehost.com/~user/page_to_redirect
to here:
http://mydomain.com/folder/new_page
I need this setup, as I am using a website's API, which requires that the callback url is ssl. And i need this redirected to my ruby on rails app.
i have configured my .htacccess (root) like so:
Options -Indexes
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mydomain.\.com$
RewriteRule ^/?$ "http\:\/\/mydomain\.com\/" [R=301,L]
Redirect /page_to_redirect http://mydomain.com/folder/new_page
the redirect works for the non ssl page:
mydomain.com/page_to_redirect
but not the ssl page:
https://secure.bluehost.com/~user/page_to_redirect
I just get a 404 error.
does anyone have any experience with this?
Bluehost support was not very helpful at all.
this is what worked:
Options -Indexes
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mydomain.\.com$
RewriteRule ^/?$ "http\:\/\/mydomain\.com\/" [R=301,L]
Redirect 301 /~mydomain/page_to_redirect http://mydomain.com/folder/new_page
This is what worked:
Options -Indexes
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mydomain.\.com$
RewriteRule ^/?$ "http\:\/\/mydomain\.com\/" [R=301,L]
Redirect 301 /~mydomain/page_to_redirect http://mydomain.com/folder/new_page

Removing .html and .php from links in IIS

As the title says, I would like to know how to remove ".html" and ".php" from links in a Windows server (IIS).
Most of the information I have found about this subject was only valid for Linux servers.
Only today I heard about the file web.config and got new material to study. Nevertheless, I am still struggling with it.
You can use the url rewrite module for IIS: http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module
Here is a good tutorial on the subject: http://www.surfingsuccess.com/asp/iis-url-rewrite.html
Read about friendly-url and .htaccess
See an example:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([a-z0-9-]+)/?$ index.php?pag=$1 [NC]
RewriteRule ^([a-z0-9-]+)/([0-9]+)/?$ index.php?pag=$1&id=$2 [NC]
</IfModule>
That way when you use:
localhost/contact
The server will do an internal redirect to:
localhost/index.php?pag=contact

redirect a url or domain with www

I have a simple question about url or domain redirect. I was looking through the previous questions on how to redirect a url or domain from http to http to force using ssl.
The weird part shows up when I try to redirect none www. to www. with the domain. I tried many ways, but none worked for me. does any one have any idea why is that?? and how to resolve this issue??
here is the code for I used at .htaccess:
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$
RewriteRule ^/?$ "https\:\/\/www\.mydomain\.com\/main" [R=301,L]
another weird thing is that whenever I typed the domain on the browser without www. there is an error message, but when I insert the www. in front of the domain, it redirects with https and wwww of course.
any idea?
Thanks
You rules will run into a loop. Do this instead:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Rewriting rails url from port 3000?

i have an applicaiton that runs at actionengineers.com:3000. How do i reqwite the application to a subdomain or directory (actionengineers.com/myapp) without disturbing the main site of course. i tried to use .htaccess file but i allways get eror 404. here is the code in the .htaccess file.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.deep.actionengeneers.com$
RewriteRule ^/?$ "http\:\/\/127\.0\.0\.1\:3000%{REQUEST_URI}" [P,QSA,L]
Try this rule:
RewriteCond %{HTTP_HOST} =www.deep.actionengeneers.com
RewriteRule ^ http://127.0.0.1:3000%{REQUEST_URI} [P,L]
Now all requests to www.deep.actionengeneers.com are getting passed through to 127.0.0.1:3000 via proxy.

How do I pass the HTTP username from Apache to Mongrel/Rails?

The goal: running a Rails application on Mongrels, allowing access through Apache after doing basic HTTP Authentication
The problem: reading the supplied username from within Rails
Apache:
<Proxy balancer://mongrel_cluster>
BalancerMember http://127.0.0.1:4001
# ...
Order deny,allow
Deny from all
AuthType Basic
AuthName "<realm>"
AuthUserFile "<users-file>"
AuthGroupFile "<groups-file>"
Require group <group>
Satisfy Any
</Proxy>
RewriteEngine On
# ...
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]
That works just fine, Apache forces the user to authenticate and forwards to Rails if successful. I omitted a few lines for handling static files and such, and triggering authentication for them as well.
The environment variables from Rails' perspective contain the usual entries and additionally HTTP_X_FORWARDED_HOST, HTTP_X_FORWARDED_SERVER and HTTP_X_FORWARDED_FOR. I was unable to pass custom environment variables by adding them to the rewrite rule:
RewriteRule ... [P,QSA,L,E=foo:bar]
Any thoughts?
Try using the RequestHeader directive to put REMOTE_USER in an HTTP header. This seems to have worked for the folks in this thread:
RewriteCond %{LA-U:REMOTE_USER} (.+)
RewriteRule . - [E=RU:%1]
RequestHeader add X-Forwarded-User %{RU}e

Resources