logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: removing file extensions with RewriteEngine doesn't work.
Author
Kanenite



Joined: 06 May 2015
Posts: 3
Location: California, Anaheim

PostPosted: Thu 07 May '15 19:07    Post subject: removing file extensions with RewriteEngine doesn't work. Reply with quote

I'm trying to accomplish a rather common task of removing file extensions, where say, instead of index.php, just index can be accessed.

I've gone through many tutorials that offer all sorts of different ways how this can be accomplished and none of it works but what's commonly given is something like this.

Code:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]


I've tried this locally and on a server remotely and it just doesn't work.

I've looked all over on stackoverflow and tried getting some help on freenode so now I'm here.

Thank you very much and if this has already been addressed on the forums, I apologize.
Back to top
Jan-E



Joined: 09 Mar 2012
Posts: 1266
Location: Amsterdam, NL, EU

PostPosted: Fri 08 May '15 7:10    Post subject: Reply with quote

Your topic title says 'removing file extensions', but your rewrite rule seems only valid for '.php'. What is your real purpose: remove only '.php'? What about things like /logo.png and /favicon.ico? Or just /?
Back to top
Kanenite



Joined: 06 May 2015
Posts: 3
Location: California, Anaheim

PostPosted: Fri 08 May '15 10:07    Post subject: Reply with quote

I'd like to focus on just php.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7405
Location: EU, Germany, Next to Hamburg

PostPosted: Sun 10 May '15 22:08    Post subject: Reply with quote

Removing the extension may only work if your urls in the html are without the ending.
I would also exclude directories from the rewriting

Code:

RewriteCond %{REQUEST_FILENAME} !-d



Not so clever would be to exclude files by extension

Code:
RewriteRule ^/(\.jpg|\.extension|\.ico) - [L]
Back to top
Kanenite



Joined: 06 May 2015
Posts: 3
Location: California, Anaheim

PostPosted: Mon 11 May '15 3:14    Post subject: Reply with quote

solved, edited the apach2.conf

<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Back to top


Reply to topic   Topic: removing file extensions with RewriteEngine doesn't work. View previous topic :: View next topic
Post new topic   Forum Index -> Apache