htaccess error leading to loop - apache

I am trying to force SSL on HTACCESS file and all my efforts result in a loop on index.php.
This is my htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
My site works fine with this but no SSL.
I tried the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ https://www.fakedomainlollol.com/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
The updated rewrite rule sends the site in a loop.
What is the error? What am I doing wrong here?

Related

how to make this htaccess for subfolder?

Can someone help me fix .htaccess to work for subfolder app installation?
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /tube
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php [L]
</IfModule>
<ifModule mod_headers.c>
Header set Access-Control-Allow-Origin: *
</ifModule>
http://yoobro.bro/tube/login&return=moderator - 404 error
I can see index once I RewriteBase /tube but nothing else seems to work. All gives me a "404 not found" error.
This .htaccess is in subdirectory, main site has .htaccess to, its wordpress site that is main and wordpress .htaccess is
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Try removing the slash before index.php
RewriteEngine On
RewriteBase /tube/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

Non-www RewriteRule not working on request URI

I need a website to have all URLs NOT have www in front of it. For this, I have found some useful bits of code here that have helped me out a lot. However, nowhere can I find how to properly do it for ALL request URIs. Currently it only works on the domains homepage.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} ^www\.domain\.nl [NC]
RewriteRule ^(.*)$ https://domain.nl%{REQUEST_URI} [L,R=301]
</IfModule>
# END WordPress
Right now www.domain.nl gets rewritten into domain.nl. However, any other like www.domain.nl/anything_else do not get rewritten (also tried adding a / before the %{REQUEST_URI}, did not work).
Any help is appreciated!
With www rule before:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.domain\.nl [NC]
RewriteRule ^ https://domain.nl%{REQUEST_URI} [NE,L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Redirect to internal path .htaccess

I just want to redirect from
mydomain.com/foo
to
mydomain.com/foo/bar
My root .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Any simple answer would be pretty appreciated.
You need to add RewriteRule ^foo/?$ /foo/bar [R=302,L] to the rewrites:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^foo/?$ /foo/bar [R=302,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Htaccess Redirect Wildcard

We have recently transferred our site to a new CMS and I am stuck on redirecting one directory.
Our old URL structure was this:
/directory/sub-directory/this-is-the-post/81281/
I want to redirect it to:
/this-is-the-post-81281
Current .htaccess file
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteEngine On
RewriteRule ^[^/]+/[^/]+/([^/]+)/([0-9]+)/?$ /$1-$2 [L,R]
#Redirected wildcard /new to forward slash.
RedirectMatch 301 /new/(.*) /$1
Put this code in your DOCUMENT_ROOT/.htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^[^/]+/[^/]+/([^/]+)/([0-9]+)/?$ /$1-$2 [L,R]
RewriteRule ^new/(.*)$ /$1 [L,R]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
What I did in our .htaccess redirects
Redirect permanent /directory/sub-directory/this-is-the-post/81281 http://www.youdomain.com/this-is-the-post-81281

htaccess - adding www redirect to current rules

I have the following .htaccess file and would like to also add redirection of non-www pages to the www equivalent:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I tried the following but would get a 500 error when trying to access anything but the root of the domain:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
These lines work for me:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^morley\.cambs\.sch\.uk$ [NC]
RewriteRule ^(.*)$ http://www.morley\.cambs\.sch\.uk/$1 [R=301,L]
That's because you don't have index.php file in your root directory.