redirecting index.html to the root using httpd.conf - redirect

I tried to redirect all index.html to root folder by configuring Apache webserver httpd.conf using settings below. It's able to redirect successfully, however it keeps pointing to testsite.com// instead of testsite.com/. Any idea why it kept forwarding to the url with 2 slash '/'? Appreciate your advice, Thanks!
RewriteEngine On
RewriteRule ^index\.html$ / [R=301,L]
RewriteRule ^(.*)/index\.html$ $1 [R=301,L]

Remove that monstrosity and use:
DirectoryIndex index.html
also for missing resources:
FallBackResource /index.html

Related

Redirection loop on OVH server

i have a domain on ovh, and so i uploaded all the file via FTP,
but when i want to redirect www.example.com to https://www.example.com/file12345.html it creates a sort of loop which makes i end up on https://www.example.com/file12345.html/file12345.html/file12345.html/file12345.html/file12345.html/file12345.html/file12345.html etc.
I have tried both using the ovh redirection rules and adding an .htaccess file in the root folder with the following code :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ https://www.example.com/file12345.html$1 [R=301,L]
The problem remains the same. Do you have any solution to that ?

Redirecting urls ending in index.php to clean url

I have a client with a strange set up. In analytics we are seeing urls getting pageviews that technically dont exist.
Example: website.org/questions/search/blog/2016/07/blog-post-name/index.php
The current ht access file looks like this but all that does is redirect these blog urls to the home page.
# Redirect index.php Requests
# ------------------------------
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{THE_REQUEST} !/system/.*
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
Is there an htaccess code to create redirect:
Example: website.org/questions/search/blog/2016/07/blog-post-name/index.php
to: website.org/questions/search/blog/2016/07/blog-post-name
Thanks

OpenShift Redirect Loop between www and non-www

I'm experiencing an infinite redirect loop when I try to access my site. The redirect loop seems to be between the non-www version and the www version.
My DNS has a URL Redirect set for http://domain.tld to www.domain.tld. Then www.domain.tld has a CNAME record for app-namespace.rhcloud.com.
For the app I added the alias www.domain.tld
I've also tried to add an alias for domain.tld, but that doesn't help.
Is there something I'm missing? Thank you very much for your help!
I'm hosting a laravel 5 project on openshift. www and non-www are tricky but I finally got it working with a simple 2 part solution...
since you can't use non-www for a cname, make it an A-record to 174.129.25.170 and they will add the www. That's all they seem to do. Weird, I know.
Use this in your .htaccess It seems to work better in cloud situations.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I found the issue. It was due to a redirect from www.domain.tld to domain.tld that was caused by a rewrite rule in the .htaccess file:
<IfModule mod_rewrite.c>
#RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
</IfModule>
Removing this resolved the issue.

How do I redirect from "domain.com/folder/index.html" to "domain.com/folder"

My site runs on nginx
I have the code to redirect my root index.html to domain name but I don't know how to redirect index.html files in folders to point to the folder for 301 redirect
example root/folder/index.html to root/folder
this code worked in htaccess to redirect root index.html to domain name
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://%{HTTP_HOST}/ [R=301,L]

redirecting a subdomain to a domain using htaccess

I would like to redirect a subdomain to a folder in its main domain. The subdomain is blog.mydomain.com and I would like to redirect it to http://www.mydomain.com/blog.
I have tried to do this using an htaccess file as follows:
RewriteEngine on
Options +FollowSymlinks -MultiViews
RewriteCond %{SERVER_PORT} =80
RewriteCond 5{HTTP-HOST} ^blog.mydomain.com$ [NC]
RewriteRule ^(.*)$ /blog/$1 [PT,L]
but it doesn't work (the redirection does not happen).
Does anyone know how I could do this?
Thank you.
Try with
Redirect 301 / http://www.mydomain.com/blog
If that doesn't work,i'll try something else