Forum Moderators: phranque

Message Too Old, No Replies

remove index.php from URL

         

lser

6:56 pm on Oct 4, 2005 (gmt 0)

10+ Year Member



Hi All,

I`m looking for rewrite rule which will translate url from

exmaple.com/index.php/en/folder1/news1

to

example.com/en/folder1/news1/

In other words, I want to remove index.php from my URL.
When user will access www.example.com/en/folder1/news1/ mod_rewrite will look in www.exmaple.com/index.php/en/folder1/news1.

I`m not strong in writing reqular expressions.

Thank you for any help.

Longhaired Genius

7:55 pm on Oct 4, 2005 (gmt 0)

10+ Year Member



How did you get to example.com/index.php/en/folder1/news1 in the first place? Didn't that involve some rewriting? You may not have given us all the information we need to help you in the most efficient way.

lser

8:04 pm on Oct 4, 2005 (gmt 0)

10+ Year Member



example.com/index.php/en/folder1/news1/

It comes from PHP script (CMS) which uses accept-path-info for reading variables from URI. En is language code.

lser

7:13 pm on Oct 5, 2005 (gmt 0)

10+ Year Member



*bump*

I`m using PHP script in my CMS which reads data from PATH_INFO

<?php
$arrParams = array();
$arrParams = explode( '/', substr( $_SERVER['PATH_INFO'], 1) );
echo '<pre>';
var_export( $arrParams );
echo '</pre>';
?>

so I have nice urls like exmaple.com/index.php/en/folder1/news1

Is possible to remove index.php from URL using mod_rewrite?

Can user access URL like example.com/en/folder1/news1/ and it will be translated to exmaple.com/index.php/en/folder1/news1

JDMorgan, could you?

Best regards

jdMorgan

7:50 pm on Oct 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want to "publish" friendlier URLs for users and search engines, then you must modify your script to output those friendlier URLs on your pages.

mod_rewrite works on *incoming* requested URLs, and takes effect as URLs are translated into filepaths or script calls -- It is not an 'output filter' that can change what appears on your pages.

Once you have published friendly URLs on your pages, then you can add mod_rewrite code -- or probably easier for you in this case, modify your script, to translate those friendly URLs back into the form needed to access your CMS/database and generate the requested next page.

Remember that a URL exists only outside the server; A server's job is to translate a URL to a filepath or to activate a script to generate content. This explains why your script must publish friendly URLs on your pages, because the links on the pages, clicked and sent in requests to your server, are the only place that URLs exist.

For more details on this, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com], particularly the first basic mod_rewrite thread in the library.

Jim