how change htaccess code, force my url to https - .htaccess

Hello and sorry about my english, im german!
I found this htaccess on github:
https://gist.github.com/HechtMediaArts/ad6cb1f190279f9eca7d
I would like to force the url to https? Which part of code i have to change?
Thanks a lot for reading!
On How to redirect all HTTP requests to HTTPS is a similar question, but i cant use it. I dont know which part of code i have to cancel to use it for my site.

I found the Solution:
Between the Lines 166 and 167
insert this Code:
# Force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Thanks to all!

Related

force index.php in url with htaccess

I've spent the last two hours reading stackoverflow and the apache manual trying to find a solution to this, but haven't found any, if a directory is access (http://domain.ext) I'd like to force index.php to appear in the url (http://domain.ext/index.php) if possible.
If anyone could help I'd really appreciate it, thank you.
RewriteEngine on
RewriteRule index.php
you can use this:
RewriteEngine on
RewriteRule ^$ /index.php?
(but you will not see it in a browser because the rewrite engine just directs to the correct file/directory without changing the url from the browser)
with [R] tag you can redirect the user so the new url would appear in the browser
I've just found what works for me
RewriteEngine On
RewriteRule ^/?$ $1/folder/index.php$2 [R=301,L]

Redirect Specific non-existing URL to an existing

I have a simple need to redirect:
mypage.com/myurl (which doesn't not exist; meening that returns a 404 error)
To
mypage.com/newurl/myurl (which is an exitsing page with content).
I saw a tons of forum post about this, but didn't find an awnser. I tried lot of thinks but with internal server error, infinitive loops etc.
Please note that I have a www to non www permanent redirect, like this:
RewriteCond %{HTTP_HOST} ^www\.mypage\.si [NC]
RewriteRule ^(.*)$ http://mypage.si/$1 [L,R=301]
UPDATE:
I will be specific:
This URL doesn't exist: http://domodom.si/sl/nepremicnine
and needs to be redirected here: http://domodom.si/sl/nepremicnine/nepremicnine-ponudba
Hope this will offer more insights about the problem.
Thanks
assuming mod_rewrite
RedirectPermanent /myurl/ mypage.com/newurl/myurl
Add this to your .htaccess file
RewriteBase /
RewriteRule ^(.*)$ newurl/$1 [NC,L]
you may want to try implementing the answer of nwellnhof in this thread.. it worked for me..

301 redirect .htaccess parameter php?fr_xyz to php?en_xyz

1st i have to say: i tried google of course. so many tips about my request - but i dont get it. maybe you can help...
it sounds simple: i want a 301 via .htaccess to a another parameter file
for example:
www.mydomain.tld/ runs without .htaccess to www.mydomain.tld/index.php?de_xyz
but:
what i want is, if you call www.mydomain.tld you get to www.mydomain.tld/index.php?en_xyz
-> ?de to ?en
if i try a simple: Redirect 301 /index.php http://www.mydomain.tld/index.php?xyz i get a redirection error on this side.
i have tried so many ways. dont get it :/
thx for your answer
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{QUERY_STRING} !(^|&)en_xyz(&|$) [NC]
RewriteRule ^/?$ %{REQUEST_URI}?en_xyz [L,QSA,R=302]
Have you tried
RewriteRule ^/?$ /index.php?en_xyz [R=301]
Note that 301 is a permanent redirect so the browser might not re-read your configuration if you redirect to a wrong address by mistake while trying.
If not working you might want to add
RewriteLog "/some/path/rewrite.log"
RewriteLogLevel 3
to your vhosts file if you have access (it might not work in .htaccess) and get the details from log.
By the way I'd prefer handling this in index.php:
header('Location: index.php?en', true, 301);

How to use redirect in htaccess for a specific url

I have a client that sent a broadcast email with a bogus link in it, like this:
http://www.exampleclient.com/%22http:/www.intendedsite.com
I'm trying to patch their .htaccess file on the server to handle this. Basically, if the url requested contains "www.intendedsite.com", I want to redirect the traffic to http://www.intendedsite.com.
I've tried a bizillion different RewriteCond/RewriteRule combinations, with no luck. Anyone got good ideas for me?
Try this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} (www\.intendedsite\.com) [NC]
RewriteRule ^ http://%1/? [L,R=301]

remove my index.php file using .htaccess

I am trying to remove the trailing index.php on my main site using .htaccess file and the following code....
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*)index\.(html?|php[45]?|[aj]spx?)\ HTTPS/
RewriteRule index\.(html?|php[45]?|[aj]spx?)$ https://www.gekkodev.com/%1 [R=301,L]
But of course it is still not working! I think the problem is my ssl certificate as that code has worked fine on lots of other sites
Any ideas would be greatly accepted!
Many thanks.
Phillip
Your RewriteCond is taking entirely the wrong approach. An HTTPS request is just an HTTP request wrapped in SSL/TLS security - it will not contain the string HTTPS in the request line, which is what you are checking for.
If you want the rule only to apply to HTTPS requests, just use the %{HTTPS} variable, as listed in the documenation:
RewriteCond %{HTTPS} on
(I've seen a lot of rewrite rules testing %{THE_REQUEST} recently, and I'm not sure why, as it should really only be used as a last resort when nothing else can work.)
Sorted this is how I have done it!
RewriteEngine on
RewriteCond %{HTTPS} on
RewriteRule index\.(html?|php[45]?|[aj]spx?)$ https://www.gekkodev.com/%1 [R=301,L]
Cheers IMSoP

Resources