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.
Related
When I try to enter my website from url www.mypage.com I got something like http://www.mypage.com/index.php/https://mypage.com/https://www.mypage.com....
When I enter from url mypage.com I got https://mypage.com - AND ITS OK
When I enter from url mypage.com/stuff I got https://mypage.com/index.php/stuff (page is working)
When I enter from url www.mypage.com/stuff I got https://mypage.com/index.php/stuff
What I should do? I would like to have always url like https://mypage.com without index.php and without 'www'.
My .htaccess :
AddHandler application/x-httpd-php70 php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
Thanks!
Try switching the order around so the internal redirect to index.php/$1 executes last:
AddHandler application/x-httpd-php70 php
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
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 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
I am trying to do something very simple yet still confusing.
I have a link
http://sub.example.com/folder/?qvar=value
I want this to be accessible via:
http://sub.example.com/folder/value
Very simple yet I cannot figure this out.
I have tried the following to no avail:
#RewriteEngine On
#RewriteRule ^(.*)$ ?qvar=$1 [L, QSA]
#RewriteRule ^(.*)$ /folder/index.php?qvar=$1 [L,QSA]
#RewriteRule ^(.*)$ index.php?qvar=$1 [L,QSA]
#RewriteRule ^(.*)$ /folder/?qvar=$1 [L,QSA]
#RewriteRule ([^/\.]+)/?$ index.php?qvar=$1 [L,QSA]
#RewriteCond %{QUERY_STRING} qvar=(.*)
#RewriteRule index.php %1 [L]
Some of these give me a 500 internal server error.
Others redirect me to /sub/sub/folder/.
Please help!
Try:
Options +FollowSymLinks -Multiviews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [NC]
RewriteCond %{THE_REQUEST} \ /folder/\?qvar=([^&\ ]+)
RewriteRule ^ /folder/%1? [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [NC]
RewriteRule ^folder/(.*)$ /folder/?qvar=$1 [L,QSA]
These rules need to be in the htaccess file in your document root
My current htaccess looks like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?site\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ index.php?page=$1
RewriteRule ^([^/\.]+)/([^/\.]+)?$ index.php?page=$1&subsectie=$2
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)?$ index.php?page=$1&subsectie=$2&subid=$3
I've edited the htaccess file. It should only use this htaccess for the main domain and not for subdomains, however subdomains still use this htaccess.
Anyone with more experience than me could point me out in the right direction? Thanks in advance.
Edit:
Here is my current (and working) htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^([^/\.]+)/([^/\.]+)?$ index.php?page=$1&subsectie=$2
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)?$ index.php?page=$1&subsectie=$2&subid=$3
Try this:
RewriteEngine On
# first, remove redirect to www by default if no subdomain
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [NC,L]
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&subsectie=$2 [NC,L]
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&subsectie=$2&subid=$3 [NC,L]