Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
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.
| |
|
Topic: removing file extensions with RewriteEngine doesn't work. |
|
Author |
|
Kanenite
Joined: 06 May 2015 Posts: 3 Location: California, Anaheim
|
Posted: Thu 07 May '15 19:07 Post subject: removing file extensions with RewriteEngine doesn't work. |
|
|
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
|
Posted: Fri 08 May '15 7:10 Post subject: |
|
|
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
|
Posted: Fri 08 May '15 10:07 Post subject: |
|
|
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
|
Posted: Sun 10 May '15 22:08 Post subject: |
|
|
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
|
Posted: Mon 11 May '15 3:14 Post subject: |
|
|
solved, edited the apach2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory> |
|
Back to top |
|
|
|
|
|
|