salve, per evitare contenuti duplicati vorrei fare un redirect da www a senza www , qualcuno sa dirmi il codice che devo inserire.
salve, per evitare contenuti duplicati vorrei fare un redirect da www a senza www , qualcuno sa dirmi il codice che devo inserire.
Aggiungi questo al tuo file .htaccess:
FonteCodice PHP:
RewriteCond %{HTTP_HOST} !^studentincrisi.altervista.org$ [NC]
RewriteRule ^(.*)$ http://studentincrisi.altervista.org/$1 [R=301,L]
ciao miki grazie per la risposta, la stringa che mi suggerisci di inserire reindirizza solo la home del sito o l'intero sito?
miki la stringa che mi hai suggerito funziona solo se entro nel sito dalla home (tutto il sito è senza www)...mentre se entro tramite una pagina con www resta tale e quale...è normale?
Effettivamente non è una cosa normale. Probabilmente è colpa di Joomla perchè sul mio sito non lo fa questo problema.
Puoi provare ad eliminare il mio codice o specificare che non vale per la sola cartella joomla ed impostare (tramite opzione o plugin) la rimozione di "www" dall'url direttamente da Joomla.
scusa ma non sono espertissimo, come dovrei fare ad impostare (tramite opzione) la rimozione di www dall'url direttamente da joomla?
Puoi aggiungere quel codice .htaccess scritto sopra dopo quello di joomla oppure inserire questo codice nel file index.php prima dell'attuale contenuto:
Codice PHP:
function redirectURLNoWWW() {
$currentURL = "";
($_SERVER["HTTPS"] == "on")? $currentURL = 'https://' : $currentURL = 'http://';
$currentURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
$currentURLNoWWW = str_replace("http://www.", "http://", $currentURL);
$currentURLNoWWW = str_replace("https://www.", "https://", $currentURL);
if ($currentURLNoWWW != $currentURL)
header("Location:".$currentURLNoWWW, TRUE, 301);
}
redirectURLNoWWW();
miki ho inserito come hai detto il codice
RewriteCond %{HTTP_HOST} !^studentincrisi.altervista.org$ [NC]
RewriteRule ^(.*)$ http://studentincrisi.altervista.org/$1 [R=301,L]
nel file .htaccess
ora pur con il file .htaccess originale le pagine con www mi restituiscono questa pagina di errore
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, info@altervista.org and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
Mi sapresti dire il perchè?
ho fatto un backup miki.... sicuramente avro fatto confusione....perchè mi ritrovo il file htaccess nella root....poi l'altro htaccess nella cartella di joomla insieme al file htaccess.txt... In quale dei due htaccess devo inserire il codice
RewriteCond %{HTTP_HOST} !^studentincrisi.altervista.org$ [NC]
RewriteRule ^(.*)$ http://studentincrisi.altervista.org/$1 [R=301,L]
Va bene qua? devo inserirlo alla fine?
##
# @version $Id: htaccess.txt 21101 2011-04-07 15:47:33Z dextercowley $
# @package Joomla
# @copyright Copyright (C) 2005 - 2011 Open Source Matters. All rights reserved.
# @license GNU General Public License version 2 or later; see LICENSE.txt
##
##
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE!
#
# The line just below this section: 'Options +FollowSymLinks' may cause problems
# with some server configurations. It is required for use of mod_rewrite, but may already
# be set by your server administrator in a way that dissallows changing it in
# your .htaccess file. If using it causes your server to error out, comment it out (add # to
# beginning of line), reload your site in your browser and test your sef url's. If they work,
# it has been set by your server administrator and you do not need it set here.
##
## Can be commented out if causes errors, see notes above.
Options +FollowSymLinks
## Mod_rewrite in use.
RewriteEngine On
## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site block out the operations listed below
# This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.
## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
## End - Custom redirects
##
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).
##
# /* modifica */
RewriteBase /joomla/
# /* fine */
## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is for something within the component folder,
# or for the site root, or for an extensionless URL, or the
# requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.
# /* modifica */
# # av:php5-engine
AddHandler av-php5 .php
# /* fine */
Ultima modifica di studentincrisi : 14-10-2014 alle ore 19.03.33
inserendolo alla fine di questo codice htaccess tutte le pagine con www mi portano alla homepage del sito
Usa questo:
Codice PHP:
RewriteEngine On
RewriteBase /joomla/
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
# # av:php5-engine
AddHandler av-php5 .php
## Elimina WWW
RewriteCond %{HTTP_HOST} !^studentincrisi.altervista.org$ [NC]
RewriteRule ^(.*)$ http://studentincrisi.altervista.org/joomla/$1 [R=301,L]
scusa miki questo codice dove dovrei inserirlo?
anche inserendo questo codice nel file htaccess tutte la pafine con www mi rimandano alla homepage del sito :-(
miki ho inserito il codice
RewriteCond %{HTTP_HOST} !^studentincrisi.altervista.org$ [NC]
RewriteRule ^(.*)$ http://studentincrisi.altervista.org/$1 [R=301,L]
nel file htaccess della root mi reindirizza solo la home page da www a non www mentre le altre pagine non vengono reindirizzate, facendo un esame con il tool VIRANTE mi dice però che tutto va bene e non riscontra contrasti tra www e non www
credo che per adesso lascerò cosi, non voglio rifare un backup. Se poi hai qualche altro suggerimento :-)
Piano! Prima di fare 3000 post aspetta un attimo. Non sono un robot che sta collegato 24h al giorno (o almeno non ancora)
Quel codice andava inserito nella cartella joomla e dopo averlo fatto e salvato le modifiche va cancellata la cache del browser che potrebbe ricordarsi del vecchio 301.
ahah scusa miki hai ragione.... comunque ho risolto mettendo il codice k hai suggerito alla fine del file htaccess nella root di joomla e poi facendo dei redirect301 delle singole pagine e tutto funziona regolarmente.... avevo fatto come suggerito da te ma pur cancellando la cache del browser non funzionava