Welcome to WebmasterWorld Guest from 54.158.237.30

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Remove /index.php/page from URLs

     
11:38 am on Nov 2, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 11, 2007
posts:97
votes: 0


Hello,

I have a new website in development whose URLs are like:

www.example.com/index.php/page/file-name

Now I would like to strip the "/index.php/page" part from the URL so that the URL becomes

www.example.com/file-name

Also there are some that have URLs like

www.example.com/index.php/file-name

From which I would like to remove the /index.php part as well.

Kindly advise, thanks!

9:29 pm on Nov 2, 2009 (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


Link to the new URLs from the pages of the site.

Set up a rewrite to accept those incoming URL requests and fetch the correct internal path for the content.

Set up an external redirect such that requests for the unwanted URL format are redirected to make a new request for the correct URL.

There's many similar examples in prior threads. Post your best effort code as a basis for discussion.

10:48 am on Nov 3, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 11, 2007
posts:97
votes: 0


Ok...it was built using CodeIgniter and this code helped fix it:

RewriteEngine on
RewriteCond $1 !^(index\.php¦images¦robots\.txt)
RewriteRule ^(.*)$ /index.php/page/$1 [L]

Working on the redirects now...

Thanks again!

11:08 am on Nov 3, 2009 (gmt 0)

Senior Member from US 

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

joined:Apr 14, 2008
posts:2910
votes: 62


The redirects are going to be quite a bit trickier, because you are probably going to need to detect an external request and Redirect it, then Rewrite internal requests to index.php so you can serve the information, and unfortunately there are lots of examples here, but this is one of those 'very specific' situations... The following should give you a specific starting point, but you are going to need to work on the Rewrite to serve the information.

I highly recommend testing all code on a test site or in a test directory before trying this live. What I post below should Redirect as you are asking, but it will NOT rewrite so you can serve the information. IOW: This is only a portion of the code you need, and I'll leave it to you (and others) to figure out (or explain) what it does and how to incorporate it with the rest of what you need.

RewriteEngine on

RewriteRule %{THE_REQUEST} ^[A-Z]{2,6}\ /index.php
RewriteRule ^index\.php/(page/)?([^.]+)$ http://www.example.com/$2 [R=301,L]

NOTE: Check out the library, links at the top left of the forum pages, specifically, jdMorgan's post about making URLs 'search engine friendly', because it will probably describe what you need to do and what this does most accurately, even if it's not the 'specific solution' to your problem.

7:06 pm on Nov 3, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 11, 2007
posts:97
votes: 0


Thanks a lot MadScientist.

We are trying all this on our test server and not on the live site. I will try this code and post feedback here.

Thanks again!

12:18 am on Nov 4, 2009 (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


We are trying all this on our test server.

If only everyone did this. Sigh!