Redirect all URL with index.php to new SEF URL

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

Moderator: General Support Moderators

Locked
Cyclones
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Thu Apr 15, 2010 5:53 pm

Redirect all URL with index.php to new SEF URL

Post by Cyclones » Thu Jul 03, 2014 12:09 pm

Hey there everyone,

I've seen this a lot in this forum and I've tried to use the code that I've found along with the code already found in my htaccess file. BUT, I can't get it to work, Basically I want to get all URL's with index.php to now forward to the respective SEF URL that has been turned on so that all the Google search responses will now forward to the correct URL.
Example: http://www.MyDomain.com/index.php/services/lawncare should forward to http://www.MyDomain.com/services/lawncare

Like I mentioned, it's not that I haven't found the code, I just can't seem to get it to work with my htaccess file. Here is one of the posts here http://forum.joomla.org/viewtopic.php?f=618&t=614279

and here is my htaccess code with the domain name changed.

### ===========================================================================
### Security Enhanced & Highly Optimized .htaccess File for Joomla!
### automatically generated by Admin Tools 2.2.10 on 2013-04-04 23:45:00 GMT
### Auto-detected Apache version: 2.0 (best guess)
### ===========================================================================
###
### The contents of this file are based on the same author's work "Master
### .htaccess", published on http://snipt.net/nikosdion/the-master-htaccess
###
### Admin Tools is Free Software, distributed under the terms of the GNU
### General Public License version 3 or, at your option, any later version
### published by the Free Software Foundation.
###
### !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! IMPORTANT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
### !! !!
### !! If you get an Internal Server Error 500 or a blank page when trying !!
### !! to access your site, remove this file and try tweaking its settings !!
### !! in the back-end of the Admin Tools component. !!
### !! !!
### !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
###

##### RewriteEngine enabled - BEGIN
RewriteEngine On
##### RewriteEngine enabled - END


#### Redirect the non-www address to the www
RewriteCond %{HTTP_HOST} !^www\.DomainName\.com
RewriteRule (.*) http://www.DomainName.com/$1


##### RewriteBase set - BEGIN
RewriteBase /
##### RewriteBase set - END

##### File execution order -- BEGIN
DirectoryIndex index.php index.html
##### File execution order -- END

##### No directory listings -- BEGIN
IndexIgnore *
Options All -Indexes
##### No directory listings -- END

##### Redirect index.php to / -- BEGIN
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.DomainName.com/ [R,L]
##### Redirect index.php to / -- END
##### Rewrite rules to block out some common exploits -- BEGIN
RewriteCond %{QUERY_STRING} proc/self/environ [OR]
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
RewriteCond %{QUERY_STRING} base64_(en|de)code\(.*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F]
##### Rewrite rules to block out some common exploits -- END
##### File injection protection -- BEGIN
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=http:// [OR]
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=(\.\.//?)+ [OR]
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=/([a-z0-9_.]//?)+ [NC]
RewriteRule .* - [F]
##### File injection protection -- END

##### Advanced server protection rules exceptions -- BEGIN
RewriteRule ^administrator\/components\/com_akeeba\/restore\.php$ - [L]
RewriteRule ^administrator\/components\/com_admintools\/restore\.php$ - [L]
RewriteRule ^plugins\/system\/bfnetwork/ - [L]
##### Advanced server protection rules exceptions -- END

##### Advanced server protection -- BEGIN

RewriteCond %{QUERY_STRING} \=PHP[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12} [NC]
RewriteRule .* - [F]
## Back-end protection
RewriteRule ^administrator/?$ - [L]
RewriteRule ^administrator/index\.(php|html?)$ - [L]
RewriteRule ^administrator/index[23]\.php$ - [L]
RewriteRule ^administrator/(components|modules|templates|images|plugins)/.*\.(jpe|jpg|jpeg|jp2|jpe2|png|gif|bmp|css|js|swf|html|mpg|mp3|mpeg|mp4|avi|wav|ogg|ogv|xls|xlsx|doc|docx|ppt|pptx|zip|rar|

pdf|xps|txt|7z|svg|odt|ods|odp|flv|mov|htm|ttf|woff|eot)$ - [L]
RewriteRule ^administrator/ - [F]
## Explicitly allow access only to XML-RPC's xmlrpc/index.php or plain xmlrpc/ directory
RewriteRule ^xmlrpc/(index\.php)?$ - [L]
RewriteRule ^xmlrpc/ - [F]
## Allow limited access for certain Joomla! system directories with client-accessible content
RewriteRule ^(components|modules|templates|images|plugins|media|libraries)/.*\.(jpe|jpg|jpeg|jp2|jpe2|png|gif|bmp|css|js|swf|html|mpg|mp3|mpeg|mp4|avi|wav|ogg|ogv|xls|xlsx|doc|docx|ppt|pptx|zip|rar|

pdf|xps|txt|7z|svg|odt|ods|odp|flv|mov|ico|htm|ttf|woff|eot)$ - [L]
RewriteRule ^(components|modules|templates|images|plugins|media|libraries)/ - [F]
## Disallow front-end access for certain Joomla! system directories (unless access to their files is allowed above)
RewriteRule ^includes/js/ - [L]
RewriteRule ^(cache|includes|language|logs|tmp)/ - [F]

## Disallow access to rogue PHP files throughout the site, unless they are explicitly allowed
RewriteCond %{REQUEST_FILENAME} (\.php)$
RewriteCond %{REQUEST_FILENAME} !(/index[23]?\.php)$
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule (.*\.php)$ - [F]
## Disallow access to htaccess.txt, php.ini and configuration.php-dist
RewriteRule ^(htaccess\.txt|configuration\.php-dist|php\.ini)$ - [F]
##### Advanced server protection -- END

##### Joomla! core SEF Section -- BEGIN
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|raw|ini|zip|json|file|vcf))$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
##### Joomla! core SEF Section -- END


Thanks for any help you guys can give to me on this.

waarnemer
Joomla! Hero
Joomla! Hero
Posts: 2954
Joined: Sun May 04, 2008 12:37 pm

Re: Redirect all URL with index.php to new SEF URL

Post by waarnemer » Thu Jul 03, 2014 1:44 pm

well in globale settings you only have to enable search friendly urls, url rewriting and in your sites root change htaccess.txt to .htaccess.. that's it...

Cyclones
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Thu Apr 15, 2010 5:53 pm

Re: Redirect all URL with index.php to new SEF URL

Post by Cyclones » Thu Jul 03, 2014 1:57 pm

waarnemer wrote:well in globale settings you only have to enable search friendly urls, url rewriting and in your sites root change htaccess.txt to .htaccess.. that's it...
Hey there waarnemer, Thanks for looking at this but that is not the problem. SEF Url's are already enabled and functioning. When the site is found in Google it still refrences the older URL's with the index.php. I am trying to forward those to the right URL's as instructed by our SEO Associate.

waarnemer
Joomla! Hero
Joomla! Hero
Posts: 2954
Joined: Sun May 04, 2008 12:37 pm

Re: Redirect all URL with index.php to new SEF URL

Post by waarnemer » Thu Jul 03, 2014 4:00 pm

set a canonical as the pages will allways be accessible including the index.php (or even with the none rewritten urls) which is good as links made in the past stay accessible but is lowsy for indexing..

I see you are in J 1.5 i have one for 2.5+ (even works in 3 but that it does not say) but pages says it has a 1.5 unsupported.. I don't know if it is exactly the same in functionality, but you can give it a try...

http://www.shikle.com/metagenerator.htm

Cyclones
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Thu Apr 15, 2010 5:53 pm

Re: Redirect all URL with index.php to new SEF URL

Post by Cyclones » Thu Jul 03, 2014 4:27 pm

waarnemer wrote:set a canonical as the pages will allways be accessible including the index.php (or even with the none rewritten urls) which is good as links made in the past stay accessible but is lowsy for indexing..

I see you are in J 1.5 i have one for 2.5+ (even works in 3 but that it does not say) but pages says it has a 1.5 unsupported.. I don't know if it is exactly the same in functionality, but you can give it a try...

http://www.shikle.com/metagenerator.htm
Hey there waarnemer, I really do appreciate you taking the time to reply but I really need to do what was asked of me by my boss. The person doing the SEO to our website has sold it to my boss so it has been given to me to have all the URL's with index.php forward to the new URL without it. I've seen examples of code that people say has worked in their htaccess file. I just can't seem to get it to work in ours.

Thanks again for trying.

User avatar
dpacadmin
Joomla! Champion
Joomla! Champion
Posts: 6029
Joined: Sat Aug 16, 2008 1:46 pm
Location: the Bat Cave
Contact:

Re: Redirect all URL with index.php to new SEF URL

Post by dpacadmin » Thu Jul 03, 2014 7:15 pm

Did you try the simpler one

Code: Select all


##### Redirect index.php to / -- BEGIN
RewriteRule ^index\.php/(.+)$ http://www.example.com/$1 [R=301,L]
##### Redirect index.php to / -- END
Replace example.com with your domain name.

Cyclones
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Thu Apr 15, 2010 5:53 pm

Re: Redirect all URL with index.php to new SEF URL

Post by Cyclones » Thu Jul 03, 2014 7:27 pm

dpacadmin wrote:Did you try the simpler one

Code: Select all


##### Redirect index.php to / -- BEGIN
RewriteRule ^index\.php/(.+)$ http://www.example.com/$1 [R=301,L]
##### Redirect index.php to / -- END
Replace example.com with your domain name.
Thanks for the reply dpacadmin, this may be a dumb question but where can I append your code within the htaccess code I provided? Is there a specific spot that will work?

User avatar
dpacadmin
Joomla! Champion
Joomla! Champion
Posts: 6029
Joined: Sat Aug 16, 2008 1:46 pm
Location: the Bat Cave
Contact:

Re: Redirect all URL with index.php to new SEF URL

Post by dpacadmin » Thu Jul 03, 2014 7:32 pm

I took what you had in your htaccess file between the begin and end lines and replaced it with the one line

Code: Select all

##### Redirect index.php to / -- BEGIN


##### Redirect index.php to / -- END

waarnemer
Joomla! Hero
Joomla! Hero
Posts: 2954
Joined: Sun May 04, 2008 12:37 pm

Re: Redirect all URL with index.php to new SEF URL

Post by waarnemer » Fri Jul 04, 2014 7:01 am

You can do a rewrite in your htaccess, but still your pages will be accessible by the url including the index.php... so If your SEO does not want to see these indexed, you will need to write the canonical... or you will want to create status 404 for these URLs? don't think so...

Cyclones
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Thu Apr 15, 2010 5:53 pm

Re: Redirect all URL with index.php to new SEF URL

Post by Cyclones » Tue Jul 08, 2014 6:56 pm

Cyclones wrote:
dpacadmin wrote:Did you try the simpler one

Code: Select all


##### Redirect index.php to / -- BEGIN
RewriteRule ^index\.php/(.+)$ http://www.example.com/$1 [R=301,L]
##### Redirect index.php to / -- END
Replace example.com with your domain name.
Thanks for the reply dpacadmin, this may be a dumb question but where can I append your code within the htaccess code I provided? Is there a specific spot that will work?
Sorry I was out of town for a few days. I've tried that code and it just redirects me back to the Homepage for the website. Thanks for trying.

User avatar
dpacadmin
Joomla! Champion
Joomla! Champion
Posts: 6029
Joined: Sat Aug 16, 2008 1:46 pm
Location: the Bat Cave
Contact:

Re: Redirect all URL with index.php to new SEF URL

Post by dpacadmin » Tue Jul 08, 2014 7:30 pm

Looking at your original code if you modify it like this does it work

Code: Select all

RewriteCond %{THE_REQUEST} !^POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.DomainName.com/ [R=301,L]
I removed the Port, don't know if it is needed and I removed the %2, guess that is in case you use https , you will need to add your domain.


Locked

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