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.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
brendanhedges
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 227
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: 235
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 /
Joomla Serbian Latin Coordinator
https://volunteers.joomla.org/joomlers/ ... oran-nesic

Power is knowledge and knowledge is power.
https://regenesiscomputers.com

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2869
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: 227
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: 44029
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
"When I'm right no one remembers but when I'm wrong no one forgets".


Locked

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