Redirect /index.php permanently?

Discuss Search Engine Optimization in relation to Joomla!. This forum will also have discussions on SEF/SEO Joomla! extensions.

Moderator: General Support Moderators

g1smd
Joomla! Guru
Joomla! Guru
Posts: 951
Joined: Mon Feb 21, 2011 4:02 pm
Location: UK

Re: Redirect /index.php permanently?

Post by g1smd » Mon Feb 06, 2012 2:42 am

All of the above code has multiple issues, not least the rules are in the wrong order and will invoke an unwanted multiple step redirection chain for some requests.

There's also syntax errors, and the code fails to redirect all non-canonical URL variants due to poor pattern matching/anchoring.

The example htaccess code also comes from very old versions of the file and there are several problems in that code. You should update your htaccess file to use the one from the current version of Joomla. You can get it from the Joomla install file. It's called htaccess.txt there. You should update that file even if you intend to continue using an older version of Joomla.

hi i have the same issue but i don't know where i add the code for redirection??
If you get the newest version of the htaccess file from the latest Joomla installer, it shows exactly where within the htaccess file any redirects should be added.

You'll also need this:

Code: Select all

########## Begin - 301 Redirect
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(index|home)\.html?\ HTTP/
RewriteRule ^(([^/]+/)*)(index|home)\.html?$ http://www.example.com/$1 [R=301,L]
#
RewriteCond %{THE_REQUEST} !^POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteCond %{SERVER_PORT}>s ^(443>(s)|[0-9]+>s)$
RewriteRule ^(([^/]+/)*)index\.php$ http%2://www.example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
########## End - 301 Redirect
Online since 1995.

WPklub
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Tue Sep 18, 2012 10:26 am

Re: Redirect /index.php permanently?

Post by WPklub » Thu Jan 31, 2013 1:28 pm

HI

I can implement site not showing index.php through joomla global configuration. Then all URLs are normal without index.php.

But then all the links on facebook or internal links are not working because they point on www.url.si/index.php/news/...

What MOD Rewrite 301 lines to use to be able to redirect all links pointing to index.php in the middle of URL to URL´s without it?

WPklub
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Tue Sep 18, 2012 10:26 am

Re: Redirect /index.php permanently?

Post by WPklub » Sat Feb 02, 2013 4:16 pm

WPklub wrote:HI

I can implement site not showing index.php through joomla global configuration. Then all URLs are normal without index.php.

But then all the links on facebook or internal links are not working because they point on http://www.url.si/index.php/news/...

What MOD Rewrite 301 lines to use to be able to redirect all links pointing to index.php in the middle of URL to URL´s without it?
RewriteRule ^index\.php/(.*) //$1 [R=301,L]

Is this ok?

g1smd
Joomla! Guru
Joomla! Guru
Posts: 951
Joined: Mon Feb 21, 2011 4:02 pm
Location: UK

Re: Redirect /index.php permanently?

Post by g1smd » Sun Feb 10, 2013 9:55 pm

Absolutely not.

You need quite a bit more code around that. At the least, the target URL should include protocol and hostname.

The good news is that I've posted it many times before if you look back through this and other threads.
Online since 1995.

mtmemon
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Wed Feb 12, 2014 8:53 pm

Re: Redirect /index.php permanently?

Post by mtmemon » Wed Feb 12, 2014 9:30 pm

First of all thank you very much for all the information this was really helpful. I have another related problem that I need assistance with. I need to redirect the below link to root as well:

http://www.mysite.com/index.php?option= ... 1&Itemid=2

I used the code to redirect index.php to root and it worked, but in this case it just remove index.php from the above link and leave the rest as is. Below is the part of code from my .htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/administrator
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^index(.*) http://www.mysite.com [R=301,L]

########## 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!
#
## Deny access to extension xml files (uncomment out to activate)
#<Files ~ "\.xml$">
#Order allow,deny
#Deny from all
#Satisfy all
#</Files>
## End of deny access to extension xml files
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%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})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
#Rewrite for the .html to without .html


Kindly let me know how I can fix this.

Thanks!!

flashpointmm
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 154
Joined: Wed Aug 25, 2010 11:10 pm
Location: Australia

Re: Redirect /index.php permanently?

Post by flashpointmm » Mon Mar 27, 2017 3:32 am

I have tried adding the following code to my .htaccess file as suggested by cad_designer

## Begin - Custom redirects
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.hpshutters\.com\.au
RewriteRule (.*) http://www.hpshutters.com.au/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ http://www.. [R=301,L]
RewriteCond %{REQUEST_URI} !^/administrator
## End - Custom redirects

When I try to go to http://www.hpshutters.com.au/index.php it redirects to http://www..
Server Not Found

I tried changing the line
RewriteRule ^(.*)index.php$ http://www.. [R=301,L]
to
RewriteRule ^(.*)index.php$ http://www.hpshutters.com.au/ [R=301,L]
but that hasn't helped.

Have I added the code correctly? I can access the /administrator backend so the last line of the code appears to work ok, just not /index.php redirect

Perhaps there is another way to achieve this...

flashpointmm
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 154
Joined: Wed Aug 25, 2010 11:10 pm
Location: Australia

Re: Redirect /index.php permanently?

Post by flashpointmm » Mon Mar 27, 2017 3:48 am

I have since tried using the code g1smb suggested and it now works :)


## Begin - Custom redirects
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(index|home)\.html?\ HTTP/
RewriteRule ^(([^/]+/)*)(index|home)\.html?$ http://www.hpshutters.com.au/$1 [R=301,L]
#
RewriteCond %{THE_REQUEST} !^POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteCond %{SERVER_PORT}>s ^(443>(s)|[0-9]+>s)$
RewriteRule ^(([^/]+/)*)index\.php$ http%2://www.hpshutters.com.au/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} !^(www\.hpshutters\.com\.au)?$
RewriteRule (.*) http://www.hpshutters.com.au/$1 [R=301,L]
#
## End - Custom redirects

khaivan92
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Thu Jun 15, 2017 2:59 pm

Re: Redirect /index.php permanently?

Post by khaivan92 » Fri Jun 23, 2017 8:33 am

you redirect 301 on .htaccess

RewriteCond %{THE_REQUEST} ^.*\/index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]


Locked

Return to “Search Engine Optimization (Joomla! SEO) in Joomla! 1.5”