Forum Moderators: phranque
<?php header('Content-type: text/html; charset=utf-8');
if ( $_SERVER['HTTPS'] )
{
$host = $_SERVER['HTTP_HOST'];
$request_uri = $_SERVER['REQUEST_URI'];
$good_url = "http://" . $host . $request_uri;
header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: $good_url" );
exit;
}
?>
AddType application/x-httpd-php5 .htm .html
RewriteEngine On
# REDIRECT htm INDEX PAGES to index/
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html?\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html?$ http://www.example.com/$1 [R=301,L]
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html?\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html?$ https://www.example.com/$1 [R=301,L]
# Get rid of extra path info such as example.com/pagina1.htm/maps/ etc
RewriteRule ^((?:[^./]+/)*[^./]+\.(?:html?|php))/ http://www.example.com/$1 [R=301,L]
# Redirect non-canonical to www
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTP_HOST} !^(www\.example.com\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{HTTP_HOST} !^(www\.example.com\.com)?$
RewriteRule (.*) https://www.example.com/$1 [R=301,L] [edited by: coopster at 11:01 pm (utc) on Apr 8, 2013]
[edit reason] example.com was misspelled; fixed it [/edit]
I am going to move the file physically yes, I thought that automatic changed the url name...
I suppose the rule should come after all rewrite rules I have for both http and https.
RewriteRule ^oldpath/oldfile.ext http://www.example.com/newpath/newpage.ext [R=301,L]
RewriteRule ^pets/(cat|dog|iguana|aardvark|armadillo)\.html http://www.example.com/animals/$1.php [R=301,L] RewriteRule ^pets/([a-z]+)\.html http://www.example.com/animals/$1.php [R=301,L]
What about adding an htaccess file in the folder for the other languages, just for the redirections for the files I want to move (and for future), ie small local rules just for that folder?
* Do as I say. Not as I do.
RewriteRule ^pets/(cat|dog|iguana|aardvark|armadillo)\.html http://www.example.com/animals/$1.php [R=301,L]
RewriteRule ^pets/([a-z]+)\.html http://www.example.com/animals/$1.php [R=301,L]
[edited by: coopster at 11:02 pm (utc) on Apr 8, 2013]
[edit reason] example.com was misspelled; fixed it [/edit]
[edited by: coopster at 11:03 pm (utc) on Apr 8, 2013]
[edit reason] example.com was misspelled; fixed it [/edit]
[edited by: coopster at 11:04 pm (utc) on Apr 8, 2013]
[edit reason] example.com was misspelled; fixed it [/edit]
RewriteRule ^(name_[0-9]+)\.htm http://www.example.com/reviews/$1.htm [R=301,L]
Then I tried to add a second rule right after the first like so:
RewriteRule ^(spanish/name_[0-9]+)\.htm http://www.example.com/spanish/opiniones/$1.htm [R=301,L]
And then the first stopped to work, and the second is not ok as I got this url: http://www.example.com/spanish/opiniones/spanish/name_2005.htm
And now go write out the word example in big letters, post it above the computer and memorize the spelling ;)
these are correct,
however they only work using one of them, not both together....I am stuck here:
RewriteRule ^(name_[0-9]+)\.htm http://www.example.com/reviews/$1.htm [R=301,L]
RewriteRule ^spanish/(name_[0-9]+)\.htm http://www.example.com/spanish/opiniones/$1.htm [R=301,L]
[edited by: incrediBILL at 10:19 pm (utc) on Apr 9, 2013]
[edit reason] unlinked rewrite rule [/edit]
Did not get this:
If the URLs use ".htm" both before and after the redirect, and the filename stays at the end, you may as well include it in the capture.
^(blahblah)\.htm http://www.example.com/otherplace/$1.htm [R=301,L]
is the same as
^(blahblah\.htm) http://www.example.com/otherplace/$1 [R=301,L]
You need to look at the output of the Live HTTP Headers extension for Firefox to see how many redirects are in that chain. The middle steps may give you a clue as to what extra rule is being invoked along the way.
ExpiresByType text/html "access"
ExpiresByType text/php "access"
Now since this is your own "server" you can change the config file-