HTTP Redirects
Force HTTPS on whole site
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Force HTTP on whole site
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !protected [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301]
WWW Redirects
Force non-www to www – when forcing any protocol to https
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Force non-www to www – http explicit (multi protocol)
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS} off
RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Force non-www to www – https explicit (multi protocol)
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS} on
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Force www to non-www – when forcing any protocol to https
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
Force www to non-www – http explicit (multi protocol)
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Force www to non-www – https explicit (multi protocol)
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
Joomla 3.8 Experimental URL Routing
Redirect old URLS with id to new ones
RewriteCond %{REQUEST_URI} (.*)\/(\d{1,}-|)(.*)\/(\d{1,}-|)(.*)
RewriteRule ^(.*)(\/)(.*) %1/%3/%5 [L,QSA,R=301]
Click on Joomla 3.8 Experimental URL Routing title link for more info.
Trailing Slash redirects
Remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [R=301,L]
Add trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /(.*)/$
RewriteRule ^ /%1 [R=301,L]
Remove index.php from Joomla SEF Links
Remove from middle of url
RewriteCond %{REQUEST_URI} ^/index\.php/
RewriteRule ^index.php/(.*) /$1 [R=301]
Remove from end of url
RewriteCond %{REQUEST_URI} !^.*/administrator/index\.php [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?) [NC]
RewriteRule ^ /%1 [R=301,L]
Removing the Temporary Url ~username out of Your Link
1. Comment Out with a #:
RewriteBase /~username/
2. Then add redirect, subbing out with your username:
RewriteEngine On
RedirectMatch 301 ^/~username(.*)$ $1
Redirect IP address to domain
RewriteCond %{HTTP_HOST} ^111\.111\.11\.111$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301]
Change URL from old folder to new folder
RewriteEngine On
RewriteRule ^oldfolder/(.*)$ /newfolder/$1 [R=301,NC]
Redirect pages after removing/disabling language code
RewriteEngine On
RewriteRule ^en/(.*)$ /$1 [R=301,NC]
ή
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/en(.*)$
RewriteRule ^en/(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
if you also need to remove a .html then
RewriteCond %{REQUEST_URI} ^/en(.*)$
RewriteRule ^en/(.*)\.html$ https://%{HTTP_HOST}/$1 [R=301,L]
if you need to remove a index.php and .html then
RewriteCond %{REQUEST_URI} ^/index\.php/en(.*)$
RewriteRule ^index.php/en/(.*)\.html$ https://%{HTTP_HOST}/$1 [R=301,L]
Redirect Joomla 1.0 SEF links for Joomla 3.x
RewriteBase /
RewriteRule ^content/view/(.*)$ /index.php?option=com_content&view=article&id=$1 [L,R=301]
Αυτό θα ανακατευθύνει το: http://www.mysite.com/content/view/1234/2/ --στο-- http://www.mysite.com/index.php?option=com_content&view=article&id=1234/2
Move website, remove folder name from path
RewriteCond %{THE_REQUEST} ^GET\ /folder/(.*)
RewriteCond %{THE_REQUEST} ^GET\ /folder/(.*)
RewriteRule ^folder/(.*) http://www.example.com/index.php/$1 [L,R=301]
και η πιο σύντομη εκδοχή του:
RewriteRule ^folder/(.*)$ /$1 [L,R=301]
Remove .html from URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
Συχνά σφάλματα - 500 Server Errors
Εάν κάποιοι κανόνες δεν δουλεύουν ,βεβαιωθείτε πως έχετε ενεργό το: RewriteEngine On και έχετε δηλώσει σωστά τις πληροφορίες όπως (mydomain.gr, folder, username, κτλ)
Εάν λαμβάνετε 500 Server Error δοκιμάστε να ενεργοποιήσετε/απενεργοποιήσετε τις εντολές που ξεκινούν με: “Options,” Options +Indexes και Options +FollowSymLinks. Η χρήση αυτών, μπορεί να ποικίλει ανάλογα με τις ρυθμίσεις του Server σας από τον Hosting Provider σας.
Εάν λαμβάνετε διπλό: index.phpindex.php τότε εντοπίστε τις ακόλουθες γραμμές:
########## Begin – Rewrite rules to block out some common exploits
RewriteCond %{QUERY_STRING} proc/self/environ [OR]
και προσθέστε την παρακάτω συνθήκη:
########## Begin – Rewrite rules to block out some common exploits
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{QUERY_STRING} proc/self/environ [OR]
Βοηθητικά εργαλεία:
Μπορείτε να μεταβείτε στην παρακάτω διεύθυνση και να κάνετε έναν έλεγχο στο htaccess αρχείο σας, για πιθανά σφάλματα. .htaccess Tester.
Καλη επιτυχία και προσοχή! Αλλαγές στο htaccess μπορεί να αποδειχθούν... ιδιαίτερα επικίνδυνες!