Welcome to WebmasterWorld Guest from 54.144.57.183

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

301 redirect issue.

     
7:16 pm on Apr 1, 2014 (gmt 0)

New User

5+ Year Member

joined:Jan 23, 2011
posts: 18
votes: 0


Hi -

we have a Joomla setup example.com and the site has SEF url's turned on in the configuration so it generates URL's as.

http://www.example.com/somepage/index.phpthrows 404 error.

and
http://www.example.com/somepageWorking fine

now that part /index.php is not working and throwing a 404 and the other work is just working fine.

Is it possible to redirect all url's which have /index.php at the end of them and redirect them to the url without /index.php

for instance.

if the url is

http://www.example.com/somecategory/some-article/index.php

redirect to:
http://www.example.com/somecategory/some-article

so, just we strip index.php from the url's like we do in php using srt_replace... but just use .htaccess to do it?

Thanks
10:32 pm on Apr 1, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Standard piece of code that should be on almost every site:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ ([^/]+/)*index\.php HTTP/
RewriteRule ^(([^/]+/)*)index\.php http://www.example.com/$1 [R=301,L]


This goes before your non-www to www canonical redirect.
10:36 pm on Apr 1, 2014 (gmt 0)

New User

5+ Year Member

joined:Jan 23, 2011
posts: 18
votes: 0


let me give that a shot... i will be back :)
10:41 pm on Apr 1, 2014 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11074
votes: 106


You also need to fix your Joomla configuration settings so you are not internally linking to the /index.php URLs.
10:58 pm on Apr 1, 2014 (gmt 0)

New User

5+ Year Member

joined:Jan 23, 2011
posts: 18
votes: 0


roger that
11:35 pm on Apr 1, 2014 (gmt 0)

New User

5+ Year Member

joined:Jan 23, 2011
posts: 18
votes: 0


i got a 500 error putting this on... i even cleared everything else from the file... any other tips?
12:01 am on Apr 2, 2014 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:14253
votes: 551


Now, wait.
http://www.example.com/somecategory/some-article/index.php

redirect to:
http://www.example.com/somecategory/some-article

Those are entirely different URLs. Add an index redirect, and the first type of request would be pointed to yet a third URL,
http://www.example.com/somecategory/some-article/


Before you start messing with your rules, you need to decide for yourself what you want the URLs to look like. Either with trailing slash or without; not both.

i got a 500 error putting this on... i even cleared everything else from the file... any other tips?

You mean your htaccess file consists, in its entirety, of those two lines-- RewriteCond followed by RewriteRule? That should have no effect at all, because the RewriteEngine hasn't been turned on. If you're using Joomla-- or any CMS-- you don't need to even consider the possibility that mod_rewrite isn't available. So there's something else going on.
3:21 am on Apr 2, 2014 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11074
votes: 106


i got a 500 error

what's in the server error log?
3:04 pm on Apr 2, 2014 (gmt 0)

New User

5+ Year Member

joined:Jan 23, 2011
posts: 18
votes: 0


Well... i can't access the server log because it's cpanel and i didn't had root access and errors weren't showing up error_log file at all.

Anyways, i got it solved using PHP as i have more experience in Joomla and PHP

Here is the code i used.


// Get the Joomla URL instance
$u =& JURI::getInstance();
// Get the complete URL
$commmonurl = $u->toString();
// Create a new URL and strip index.php from it.
$newurl = str_replace('index.php','',$commmonurl);
// let's find index.php
$found = strpos($commmonurl,'/index.php');

if found returns true then redirect user to $newurl.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members