SEO-friendly HTACCESS 301 redirect for non-www to www PLUS .php to non-.php PLUS http to htps [duplicate]
up vote
0
down vote
favorite
This question already has an answer here:
htaccess redirect to https://www
12 answers
I have a custom build non-CMS site on PHP.
The way my current .htaccess is setup is to allow me to use the urls without ".php" part and to 301 redirect all non www requests to www:
RewriteEngine On
RewriteCond %HTTP_HOST ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ $1.php [L,QSA]
Now we are switching to HTTPS.
How do I get a proper SEO-friendly redirect from http://
to https://
in .htaccess?
I've tried replacing third string with
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
but it doesn't do the trick...
Also, optionally, is there a way to set up a 301 redirect for .php request to redirect to non-.php variant? Although it looks like it means to redirect to same exact page, not sure if it will be SEO-safe to do it or maybe it will even result in a redirect loop?
php apache .htaccess redirect seo
marked as duplicate by Machavity
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 11 at 22:37
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
up vote
0
down vote
favorite
This question already has an answer here:
htaccess redirect to https://www
12 answers
I have a custom build non-CMS site on PHP.
The way my current .htaccess is setup is to allow me to use the urls without ".php" part and to 301 redirect all non www requests to www:
RewriteEngine On
RewriteCond %HTTP_HOST ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ $1.php [L,QSA]
Now we are switching to HTTPS.
How do I get a proper SEO-friendly redirect from http://
to https://
in .htaccess?
I've tried replacing third string with
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
but it doesn't do the trick...
Also, optionally, is there a way to set up a 301 redirect for .php request to redirect to non-.php variant? Although it looks like it means to redirect to same exact page, not sure if it will be SEO-safe to do it or maybe it will even result in a redirect loop?
php apache .htaccess redirect seo
marked as duplicate by Machavity
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 11 at 22:37
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This question already has an answer here:
htaccess redirect to https://www
12 answers
I have a custom build non-CMS site on PHP.
The way my current .htaccess is setup is to allow me to use the urls without ".php" part and to 301 redirect all non www requests to www:
RewriteEngine On
RewriteCond %HTTP_HOST ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ $1.php [L,QSA]
Now we are switching to HTTPS.
How do I get a proper SEO-friendly redirect from http://
to https://
in .htaccess?
I've tried replacing third string with
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
but it doesn't do the trick...
Also, optionally, is there a way to set up a 301 redirect for .php request to redirect to non-.php variant? Although it looks like it means to redirect to same exact page, not sure if it will be SEO-safe to do it or maybe it will even result in a redirect loop?
php apache .htaccess redirect seo
This question already has an answer here:
htaccess redirect to https://www
12 answers
I have a custom build non-CMS site on PHP.
The way my current .htaccess is setup is to allow me to use the urls without ".php" part and to 301 redirect all non www requests to www:
RewriteEngine On
RewriteCond %HTTP_HOST ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ $1.php [L,QSA]
Now we are switching to HTTPS.
How do I get a proper SEO-friendly redirect from http://
to https://
in .htaccess?
I've tried replacing third string with
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
but it doesn't do the trick...
Also, optionally, is there a way to set up a 301 redirect for .php request to redirect to non-.php variant? Although it looks like it means to redirect to same exact page, not sure if it will be SEO-safe to do it or maybe it will even result in a redirect loop?
This question already has an answer here:
htaccess redirect to https://www
12 answers
php apache .htaccess redirect seo
php apache .htaccess redirect seo
edited Nov 11 at 16:44
asked Nov 11 at 16:23
Acidon
50021230
50021230
marked as duplicate by Machavity
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 11 at 22:37
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Machavity
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 11 at 22:37
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
You can use the following htaccess rules (just replace example.com
with yourdomain.com
in the second RewriteCond)
RewriteEngine On
#301 redirect from http to https + non-www to www
RewriteCond ℅HTTPS off [OR]
RewriteCond ℅HTTP_HOST ^example.com$ [NC]
RewriteCond ℅HTTP_HOST (?:www.)?(.+)$
RewriteRule ^ https://www.℅1℅REQUEST_URI [NE,L,R]
#remove .php extension
#redirect to remove .php from URLs
RewriteCond ℅THE_REQUEST /(.+).php [NC]
RewriteRule ^ /℅1 [L,R=301]
#handle extension less php URLs
RewriteCond ℅REQUEST_FILENAME.php -f
RewriteRule ^(.+)/?$ /$1.php [L]
I've tried the first part (301 redirect from http to https + non-www to www), but it only redirects non-www to www, and no http to https is observed.
– Acidon
Nov 11 at 17:47
actually even worse - it is redirects all the pages to root domain...
– Acidon
Nov 11 at 17:49
@Acidon Try cleaning your browser cache.
– starkeen
Nov 11 at 18:22
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You can use the following htaccess rules (just replace example.com
with yourdomain.com
in the second RewriteCond)
RewriteEngine On
#301 redirect from http to https + non-www to www
RewriteCond ℅HTTPS off [OR]
RewriteCond ℅HTTP_HOST ^example.com$ [NC]
RewriteCond ℅HTTP_HOST (?:www.)?(.+)$
RewriteRule ^ https://www.℅1℅REQUEST_URI [NE,L,R]
#remove .php extension
#redirect to remove .php from URLs
RewriteCond ℅THE_REQUEST /(.+).php [NC]
RewriteRule ^ /℅1 [L,R=301]
#handle extension less php URLs
RewriteCond ℅REQUEST_FILENAME.php -f
RewriteRule ^(.+)/?$ /$1.php [L]
I've tried the first part (301 redirect from http to https + non-www to www), but it only redirects non-www to www, and no http to https is observed.
– Acidon
Nov 11 at 17:47
actually even worse - it is redirects all the pages to root domain...
– Acidon
Nov 11 at 17:49
@Acidon Try cleaning your browser cache.
– starkeen
Nov 11 at 18:22
add a comment |
up vote
0
down vote
You can use the following htaccess rules (just replace example.com
with yourdomain.com
in the second RewriteCond)
RewriteEngine On
#301 redirect from http to https + non-www to www
RewriteCond ℅HTTPS off [OR]
RewriteCond ℅HTTP_HOST ^example.com$ [NC]
RewriteCond ℅HTTP_HOST (?:www.)?(.+)$
RewriteRule ^ https://www.℅1℅REQUEST_URI [NE,L,R]
#remove .php extension
#redirect to remove .php from URLs
RewriteCond ℅THE_REQUEST /(.+).php [NC]
RewriteRule ^ /℅1 [L,R=301]
#handle extension less php URLs
RewriteCond ℅REQUEST_FILENAME.php -f
RewriteRule ^(.+)/?$ /$1.php [L]
I've tried the first part (301 redirect from http to https + non-www to www), but it only redirects non-www to www, and no http to https is observed.
– Acidon
Nov 11 at 17:47
actually even worse - it is redirects all the pages to root domain...
– Acidon
Nov 11 at 17:49
@Acidon Try cleaning your browser cache.
– starkeen
Nov 11 at 18:22
add a comment |
up vote
0
down vote
up vote
0
down vote
You can use the following htaccess rules (just replace example.com
with yourdomain.com
in the second RewriteCond)
RewriteEngine On
#301 redirect from http to https + non-www to www
RewriteCond ℅HTTPS off [OR]
RewriteCond ℅HTTP_HOST ^example.com$ [NC]
RewriteCond ℅HTTP_HOST (?:www.)?(.+)$
RewriteRule ^ https://www.℅1℅REQUEST_URI [NE,L,R]
#remove .php extension
#redirect to remove .php from URLs
RewriteCond ℅THE_REQUEST /(.+).php [NC]
RewriteRule ^ /℅1 [L,R=301]
#handle extension less php URLs
RewriteCond ℅REQUEST_FILENAME.php -f
RewriteRule ^(.+)/?$ /$1.php [L]
You can use the following htaccess rules (just replace example.com
with yourdomain.com
in the second RewriteCond)
RewriteEngine On
#301 redirect from http to https + non-www to www
RewriteCond ℅HTTPS off [OR]
RewriteCond ℅HTTP_HOST ^example.com$ [NC]
RewriteCond ℅HTTP_HOST (?:www.)?(.+)$
RewriteRule ^ https://www.℅1℅REQUEST_URI [NE,L,R]
#remove .php extension
#redirect to remove .php from URLs
RewriteCond ℅THE_REQUEST /(.+).php [NC]
RewriteRule ^ /℅1 [L,R=301]
#handle extension less php URLs
RewriteCond ℅REQUEST_FILENAME.php -f
RewriteRule ^(.+)/?$ /$1.php [L]
answered Nov 11 at 17:19
starkeen
29.7k145777
29.7k145777
I've tried the first part (301 redirect from http to https + non-www to www), but it only redirects non-www to www, and no http to https is observed.
– Acidon
Nov 11 at 17:47
actually even worse - it is redirects all the pages to root domain...
– Acidon
Nov 11 at 17:49
@Acidon Try cleaning your browser cache.
– starkeen
Nov 11 at 18:22
add a comment |
I've tried the first part (301 redirect from http to https + non-www to www), but it only redirects non-www to www, and no http to https is observed.
– Acidon
Nov 11 at 17:47
actually even worse - it is redirects all the pages to root domain...
– Acidon
Nov 11 at 17:49
@Acidon Try cleaning your browser cache.
– starkeen
Nov 11 at 18:22
I've tried the first part (301 redirect from http to https + non-www to www), but it only redirects non-www to www, and no http to https is observed.
– Acidon
Nov 11 at 17:47
I've tried the first part (301 redirect from http to https + non-www to www), but it only redirects non-www to www, and no http to https is observed.
– Acidon
Nov 11 at 17:47
actually even worse - it is redirects all the pages to root domain...
– Acidon
Nov 11 at 17:49
actually even worse - it is redirects all the pages to root domain...
– Acidon
Nov 11 at 17:49
@Acidon Try cleaning your browser cache.
– starkeen
Nov 11 at 18:22
@Acidon Try cleaning your browser cache.
– starkeen
Nov 11 at 18:22
add a comment |