Rewriting URL's to remove .php

11 posts by 3 authors in: Forums > CMS Builder
Last Post: May 26, 2010   (RSS)

By theclicklab - May 17, 2010

Hi,

I'm trying to rewrite urls to remove the .php from the file names, E.g.

From this:
/yacht-type.php/motor-2/

To this:
/yacht-type/motor-2/

When I do this, I get this error:
No input file specified.

The .htaccess file contains this:
RewriteEngine On
RewriteRule ^([a-z0-9-_]+)/([a-z0-9-_]+)/?$ /$1.php/$2/ [QSA,NC,L]
RewriteRule ^([a-z0-9-_]+)$ /$1/ [R=301,NC,L]
RewriteRule ^([a-z0-9-_]+)/$ /$1.php [QSA,NC,L]


Any suggestions?

Many thanks
Jan

Re: [aquaman] Rewriting URL's to remove .php

By Jason - May 18, 2010

Hi,

Try using this in your .htaccess file to remove the .php:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php


Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Rewriting URL's to remove .php

By theclicklab - May 18, 2010

Hi Jason,

That works for:
/destinations.php >> /destinations

But does not work for:
/destinations.php >> /destinations/

Or:
/yacht-type.php/motor-2/ >> /yacht-type/motor-2/

I'm getting a 500 error and this showing in the error log when I try that:

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

BTW... I have 'useSeoUrls' => true' in case thats whats causing the issue?

Thanks
Jan

Re: [Jason] Rewriting URL's to remove .php

By theclicklab - May 19, 2010

Hi Jason,

Here you go, theres nothing else in it apart from:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php


Many thanks!
Attachments:

upload_002.htaccess 1K

Re: [aquaman] Rewriting URL's to remove .php

By Jason - May 19, 2010

Hi,

Could you maybe email me a link to some of these pages so I can take a closer look.
jason@interactivetools.com

Thanks.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [aquaman] Rewriting URL's to remove .php

By Jason - May 19, 2010

Hi,

You can also try putting this code up at the top of your .htaccess file:

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]


Let me know if this works for you.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Rewriting URL's to remove .php

By theclicklab - May 19, 2010

Hi Jason, here you go, it looks like a trailing slash issue?

Scenario #1:

Original URL:
http://luxurychartergroup.dreamhosters.com/destinations.php

Without .php (works):
http://luxurychartergroup.dreamhosters.com/destination

Without .php and trailing slash (error):
http://luxurychartergroup.dreamhosters.com/destination/


Scenario #2:

Original URL:
http://luxurychartergroup.dreamhosters.com/yacht-type.php/sailing-1/

Without .php and with seo friendly variable (error):
http://luxurychartergroup.dreamhosters.com/yacht-type/sailing-1/

NOTE: when using the first variation of the .htaccess file above I did not get a server error but the following message:

No input file specified.

Which seems to be CMS related rather than an htaccess issue. So, I assume this will happen again once the .htaccess works correctly again.

I've attached the yacht-type.php page as well.

Many thanks for your persistence and help :)
Attachments:

yacht-type_001.php 6K

Re: [aquaman] Rewriting URL's to remove .php

By Jason - May 19, 2010

Hi,

Just wondering if you saw my last post. Have you tried that code? If it still isn't working, let me know.

Thanks.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Rewriting URL's to remove .php

By theclicklab - May 22, 2010

Hi Jason,

Saw that and tried it but it did not work either. I have discovered that this is to do with using:

'useSeoUrls' => true,

If I remove that, the original rewrite rules I have work fine, so must be a conflict with how this is being handled.

I could remove the useSeoUrls and build them manually e.g.

Instead of this:

<a href="/<?php echo $record['_link'] ?>">

I would need to go through and change everything to something like:

<a href="/yacht/<?php echo $record['yacht_name'] ?>-<?php echo $record['num'] ?>/">

But there must be an easier way of removing the .php extention?

At this stage, I'm almost resigned to just leaving this with the .php in the url's.

Your thoughts?

Many thanks!