How to remove index.php from url and google

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

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Post Reply
brendanhedges
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 129
Joined: Sat Mar 04, 2017 1:28 am
Location: Surrey, UK
Contact:

How to remove index.php from url and google

Post by brendanhedges » Tue Nov 13, 2018 1:47 am

Hi,
I hope someone can help me out here.

I have just revamped an old Joomla site that did not use search engine friendly urls. Obviously these are listed on google.
I have turned on the sef in the config settings and in htaccess placed the following to remove the index.php from the urls so google and the new site's urls match (hopefully!).

# RewriteBase /
# RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index.php/?([^\ \?]*) [NC]
# RewriteRule ^ %1/%2 [R=301,L]

This however broke the back-end and i could not save/change settings etc.
The front end seemed to work fine.

I wonder if someone could help me out with the code so that it only removes the index.php from the frontend and not the backend(administrator) as well. I am not an expert in 301 redirects and trying to find specific to Joomla is proving difficult.

Many thanks.

Brendan

User avatar
CyrusXxX
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 215
Joined: Wed Oct 04, 2017 6:23 am
Location: Belgrade Serbia
Contact:

Re: How to remove index.php from url and google

Post by CyrusXxX » Tue Nov 13, 2018 5:49 am

Hello brendanhedges, here is the code:

Code: Select all

########## Begin - Redirect index.php to /
## Note: Change example.com to reflect your own domain name
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://example.com/$1 [R=301,L]
## If the above line throws a 500 error, change [R=301,L] to [R,L]
########## End - Redirect index.php to /
Knowledge is power and power is knowledge.

https://regenesiscomputers.com

SharkyKZ
Joomla! Ace
Joomla! Ace
Posts: 1638
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: How to remove index.php from url and google

Post by SharkyKZ » Tue Nov 13, 2018 7:58 am

You should not redirect non-SEF URLs. That's just asking for trouble.

You can remove ? after / so that URLs containing index.php/ but not index.php are redirected.

Code: Select all

RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index.php/([^\ \?]*) [NC]
RewriteRule ^ %1/%2 [R=301,L]

brendanhedges
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 129
Joined: Sat Mar 04, 2017 1:28 am
Location: Surrey, UK
Contact:

Re: How to remove index.php from url and google

Post by brendanhedges » Tue Nov 13, 2018 9:11 am

Thank you CyrusXxX.

Your solution works as I hoped.

SharkyKZ

"You should not redirect non-SEF URLs. That's just asking for trouble." Yes, I agree. Luckily many of the more important URL's were running of menu items, so although SEF was turned off, it should be ok as they had the structure https://example.com/index.php/someplace ... herarticle etc. I just need to remove index.php from the URL to end up with https://example.com/someplace/someotherarticle.
I have just checked in Google and with Cyrus's code if I click on a search result that is http://example.com/index.php/article, i do get taken to the page http://example.com/article without a 404 error. Which was the point of this.

Many thanks.

As a side note.
Attention Admins. I don't know if it already exists, but would it not be a great idea to have a list of common 301 redirects that are specific, or peculiar to Joomla put to a sticky in this forum? I spent hours trawling through many pages of redirects for regular none cms websites, not really knowing what I was looking at. I know many redirects will be the same, but for many Joomla users who don't have much knowledge of redirects and the way in which they are written, it would be a god send.

Maybe this post could be the beginning of the list of peoples 301 redirects from the Joomla community. It would just need compiling in a couple of months to a sticky. What say you?

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 37446
Joined: Sat Apr 05, 2008 9:58 pm

Re: How to remove index.php from url and google

Post by Webdongle » Tue Nov 13, 2018 10:39 am

http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"The definition of insanity is doing the same thing over and over again, but expecting different results": Albert Einstein


Post Reply

Return to “Search Engine Optimization (Joomla! SEO) in Joomla! 3.x”