i cannot redirect my domain ip to the domain name, i have the following in my htaccess file which im told should work
RewriteCond %{HTTP_HOST} ^37\.61\.233\.81
RewriteRule (.*) http://jpcreativevision.co.uk/$1 [R=301,L]
But thats not working, anyone got any idea why it isnt working? thanks for the help.
Edit
Full htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]
RewriteCond %{HTTP_HOST} ^37\.61\.233\.81
RewriteRule (.*) http://jpcreativevision.co.uk/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^jpcreativevision\.co.uk
RewriteRule (.*) http://jpcreativevision.co.uk/$1 [R=301,L]
ErrorDocument 404 http://jpcreativevision.co.uk/404.php
Just tested it via http://htaccess.madewithlove.be/ and it says, that your rule should work as expected.
However, you may try a different order of your rules:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^37\.61\.233\.81
RewriteRule (.*) http://jpcreativevision.co.uk/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^jpcreativevision\.co.uk
RewriteRule (.*) http://jpcreativevision.co.uk/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]
ErrorDocument 404 http://jpcreativevision.co.uk/404.php
Related
I'm trying to make a redirect from one domain to another. I want to redirect in all cases to "https://myweb.com" using htaccess file. Today I have the following code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.myweb.com.ar [OR]
RewriteCond %{HTTP_HOST} ^myweb.com.ar$
RewriteRule ^(.*)$ https://www.myweb.com/ [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Let's see the results:
1) http://www.myweb.com >> OK!
2) http://www.myweb.com.ar >> OK!
3) https://www.myweb.com.ar >> ERROR, The redirect is not happenning here.
What can I try to solve this issue?
Tks in advance!
Try this rewrites, domain ar->com, http->https, www->non www, request->filename.php
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?myweb\.com\.ar [NC]
RewriteRule (.*) https://myweb.com/ [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://myweb.com%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^www.myweb.com$ [NC]
RewriteRule ^(.*)$ https://myweb.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
In my .htaccess file i have already some rewrite conditions and rules, and its working normal.
Now i need to add "http to https redirect" to my htaccess file.
Here is my old .htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteRule ^([a-z0-9_-]+)$ pages/$1.php [L]
RewriteRule ^([a-z0-9_-]+)/([-a-zA-Z0-9_]+)$ pages/$1/$2.php [L]
RewriteRule ^([a-z0-9_-]+)/([-a-zA-Z0-9_]+)/([-a-zA-Z0-9_]+)$ pages/$1/$2/$3.php [L]
I attempted to add below code to file but it doesnt work properly.
For example if i write the url direct to browser its work (only with www). But if click my any backlinks or google search result links it doesnt work.
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}/$1 [NC,R=301,L]
Where do i wrong? Where should i put the code? Any help would be great. Thanks.
your htaccess could look like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.yoursite\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteRule ^([a-z0-9_-]+)$ pages/$1.php [L]
RewriteRule ^([a-z0-9_-]+)/([-a-zA-Z0-9_]+)$ pages/$1/$2.php [L]
RewriteRule ^([a-z0-9_-]+)/([-a-zA-Z0-9_]+)/([-a-zA-Z0-9_]+)$ pages/$1/$2/$3.php [L]
At least, it works for me, in my own implementation
You can use the following htaccess :
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}/$1 [NC,R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)/?$ $1.php [L]
Clear your browser's cache before testing this
I'm using CodeIgniter.
in httacess file, I wrote this code to remove index.php from url:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Now I want to redirect site root to subdomain, with this code:
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ sub.domain.com/$1 [r=301,nc]
domain.com redirected to sub.domain.com successfully. but domain.com/dir to sub.domain.com/dir not work and still opening domain.com/dir.
When I removed first code, redirection worked perfect, but I need to remove index.php too.
Adding $to the end of rewritecond %{http_host} ^domain.com [nc] should fix it for you.
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ sub.domain.com/$1 [r=301,nc]
Would become
rewritecond %{http_host} ^domain.com$ [nc]
rewriterule ^(.*)$ sub.domain.com/$1 [r=301,nc]
Have your rules like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://sub.domain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
I plan on implementing this .htaccess code (thanks anubhava) into my website:
RewriteEngine on
rewritecond %{http_host} ^mydomain.com [nc]
rewriterule ^(.*)$ http://mydomain.com/$1 [r=301,nc]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.html -f [NC]
RewriteRule ^(.+?)/?$ $1.html [L]
ErrorDocument 404 /404.html
Basically it will change URL from "www.mydomain.com/this-page.html" into "www.mydomain.com/this-page" - it does that very well.
However, I have encountered an issue - let's say that one of my pages is "treatments.html".
URL adress will look like this "mydomain.com/treatments" and that's fine. But I want also to make a directory called "treatments" and include the list of available treatments in that folder, it would look like this
"mydomain.com/treatments/treatment-one"
"mydomain.com/treatments/treatment-two"
"mydomain.com/treatments/treatment-three"
and so on...
THE ISSUE IS:
When I try to access the file "treatments.html" browser confuses it with the directory and server sends message [403]Forbidden.
Any ideas for solution?
Ok change your last rule to:
DirectorySlash On
ErrorDocument 404 /404.html
RewriteEngine on
RewriteBase /
rewritecond %{http_host} !^mydomain\.com$ [nc]
rewriterule ^(.*)$ http://mydomain.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.html -f [NC]
RewriteRule ^(.+?)/?$ $1.html [L]
I have been scratching my head for almost half an hour already because of this. I don't know what I am doing wrong, might just be under my nose, but i just cant see it. Here's what I have on my .htaccess
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/admin [NC]
RewriteRule ^(.*)$ http://newsite.com/$1 [R=301,L]
When I access example.com/admin, i am still redirected to newsite.com/admin.
Can anyone please advise? Thanks!
UPDATE: This is my everything that I have on mod_rewrite currently:
RewriteRule ^googleabcdef12345.html - [L]
RewriteCond %{HTTP_HOST} ^sample1\.no$ [NC]
RewriteRule ^(.*)$ http://www.newsample1.no/$1 [L,R=301]
RewriteCond %{HTTP_HOST} example\.com$ [NC]
#RewriteRule admin - [S=1]
RewriteRule ^(.*)$ http://newsite.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
It is a drupal website btw. I tried QUERY_STRING instead of REQUEST_URI but no luck still.