Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Hide the .php extension from url


al3ks

Recommended Posts

Does anyone know how to remove the .php from the url on pages like shipping.php. So instead of www.mysite.com/shipping.php it would be www.mysite.com/shipping.

 

I have tried adding a rewrite rule to .htaccess like suggested by FWmedia here but it didn't work.

 

Would appreciate your help.

Regards

Find this post helpful? Click the 'Like this' button. :)

Link to comment
Share on other sites

RewriteEngine On

 

Needs to be above the code maybe also RewriteBase.

 

You posted in the USU5 support thread so I had assumed you already had this code.

Link to comment
Share on other sites

@@FWR Media Yeah I have the RewriteEngine On i have added the code to the list like you can see in the code below.

 

<IfModule mod_rewrite.c>
 RewriteEngine On

 # RewriteBase instructions
 # Change RewriteBase dependent on how your shop is accessed as below.
 # http://www.mysite.com = RewriteBase /
 # http://www.mysite.com/catalog/ = RewriteBase /catalog/
 # http://www.mysite.com/catalog/shop/ = RewriteBase /catalog/shop/

 # Change RewriteBase using the instructions above  
 RewriteBase /
 RewriteRule ^([a-z0-9-/]+)-p-([0-9]+).html$ product_info.php [NC,L,QSA]
 RewriteRule ^([a-z0-9-/]+)-c-([0-9_]+).html$ index.php [NC,L,QSA]
 RewriteRule ^([a-z0-9-/]+)-m-([0-9]+).html$ index.php [NC,L,QSA]
 RewriteRule ^([a-z0-9-/]+)-pi-([0-9]+).html$ popup_image.php [NC,L,QSA]
 RewriteRule ^([a-z0-9-/]+)-pr-([0-9]+).html$ product_reviews.php [NC,L,QSA]
 RewriteRule ^([a-z0-9-/]+)-pri-([0-9]+).html$ product_reviews_info.php [NC,L,QSA]
 # Articles contribution
 RewriteRule ^([a-z0-9-/]+)-t-([0-9_]+).html$ articles.php [NC,L,QSA]
 RewriteRule ^([a-z0-9-/]+)-au-([0-9]+).html$ articles.php [NC,L,QSA]
 RewriteRule ^([a-z0-9-/]+)-a-([0-9]+).html$ article_info.php [NC,L,QSA]
 # Information pages
 RewriteRule ^([a-z0-9-/]+)-i-([0-9]+).html$ information.php [NC,L,QSA]
 # Links contribution
 RewriteRule ^([a-z0-9-/]+)-links-([0-9_]+).html$ links.php [NC,L,QSA]
 # Newsdesk contribution
 RewriteRule ^([a-z0-9-/]+)-n-([0-9]+).html$ newsdesk_info.php [NC,L,QSA]
 RewriteRule ^([a-z0-9-/]+)-nc-([0-9]+).html$ newsdesk_index.php [NC,L,QSA]
 RewriteRule ^([a-z0-9-/]+)-nri-([0-9]+).html$ newsdesk_reviews_info.php [NC,L,QSA]
 RewriteRule ^([a-z0-9-/]+)-nra-([0-9]+).html$ newsdesk_reviews_article.php [NC,L,QSA]

RewriteRule ^(account|contact|privacy|shipping)$ $1.php [NC,L,QSA]
</IfModule>

Find this post helpful? Click the 'Like this' button. :)

Link to comment
Share on other sites

@@al3ks

 

ok well maybe there's a mis-communication about usage.

 

With that code in place have you tried accessing the site like: -

 

www.mysite.com/catalog/contact

www.mysite.com/catalog/shipping

www.mysite.com/catalog/privacy

Link to comment
Share on other sites

@@FWR Media

I have tried now and it does work when you enter www.mysite.com/shipping. So the code does work.

Do you think there is a solution to prevent the mis-communication, so that it works even when you click on a link ? (from my navigation menu).

 

Thanks for the help so far though, really appreciate it.

Find this post helpful? Click the 'Like this' button. :)

Link to comment
Share on other sites

@@al3ks

 

Your question was about .htaccess not creating links.

 

To change the links you need to change the defines in includes/filenames.php

 

Example: -

 

define('FILENAME_CONTACT_US', 'contact_us.php');

 

Becomes: -

 

define('FILENAME_CONTACT_US', 'contact');

 

Be careful though, only change the non dynamic pages, changing index.php etc would break the script.

Link to comment
Share on other sites

@@FWR Media

 

But after changing that in filenames.php there is a problem with the languages directory, i get this error:

 

Warning: require(includes/languages/english/shipping) [function.require]: failed to open stream: No such file or directory in /xxxx/xxxx/public_html/knnutrition/shipping.php on line 15

 

Fatal error: require() [function.require]: Failed opening required 'includes/languages/english/shipping' (include_path='.:/usr/lib64/php:/usr/lib/php:/usr/share/pear') in /xxxx/xxxx/public_html/knnutrition/shipping.php on line 15

Find this post helpful? Click the 'Like this' button. :)

Link to comment
Share on other sites

@@al3ks

 

Yes my mistake. You need to modify the tep_href_link() function ( includes/functions/html_output.php ) to remove the .php from the filenames in question.

Link to comment
Share on other sites

catalog/includes/functions/html_output.php

 

Find ( line 18(ish) )

 

    $page = tep_output_string($page);

 

Add imediately BELOW

 

 

   // FWR media modify static filenames
   $to_modify = array( FILENAME_SHIPPING, FILENAME_CONTACT_US, FILENAME_PRIVACY, FILENAME_ACCOUNT);
   if ( in_array( $page, $to_modify )) $page = substr( $page, 0, -4 );

Link to comment
Share on other sites

Thanks a lot, It works!

I have put the code under:

function tep_href_link( $page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $search_engine_safe = true ) {

 

because i don't have this:

$page = tep_output_string($page);

 

and it works great, just have to make sure that in the .htaccess the file names match the ones in html_output.php

 

Thanks again for your help @@FWR Media

Find this post helpful? Click the 'Like this' button. :)

Link to comment
Share on other sites

because i don't have this:

$page = tep_output_string($page);

 

Ok then put it under

 


   if (!tep_not_null($page)) {
  die('</td></tr></table></td></tr></table><br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine the page link!<br><br>');
   }

Link to comment
Share on other sites

hmm haven't got that either. Is the place I put it in wrong, because it works...

 

It'll do it seems.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...