Ubuntu 14.04LTS 32bit
LAMP
I know it's an old question but..
I need it to remove .php anywhere it finds it from the visible url. It needs to work with /showthread.php?id=XX ---> /showthread?id=XX
I can't even get it to work with /page.php
--> /page
.
I've tried these:
Remove .php extension with .htaccess
How to hide the .html extension with Apache mod_rewrite
Remove .php from urls with htaccess
It just does nothing at all.
While other .htaccess
code works fine..
While
<?php
phpinfo();
Lists mod_rewrite in Loaded Modules
And
<?php
if(!function_exists('apache_get_modules') ){ phpinfo(); exit; }
$res = 'Module Unavailable';
if(in_array('mod_rewrite',apache_get_modules()))
$res = 'Module Available';
?>
<html>
<head>
<body>
<p><?php echo apache_get_version(),"</p><p>mod_rewrite $res"; ?></p>
</body>
</html>
Returns Module Available
Tried many more things
# Apache Rewrite Rules
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Add trailing slash to url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ $1/ [R=301,L]
# Remove .php-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.php
# End of Apache Rewrite Rules
</IfModule>
#
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
#
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
Not even this has any effect whatsoever:
RewriteRule ^page$ page.php [L]
sudo service apache2 restart
does not change anything.
Server reboot changes nothing.
I tried clearing other code inside, did not make any change.
I cleared my browser cache 100 times
I'm starting to think that it just hates me. What could possible be causing this??
Hope helped.
It's worked for me.
Maybe this could be a duplicate but take a look at this:
How to remove .html from URL
Just in the solution change the
hmtl
forphp
Check this link.
This is the answer using .htaccess:
Tested it on Windows with WAMP and working.
Assuming that .htaccess is being processed, then this super simple .htaccess should work for you:
If it doesn't work, there is something wrong with your Apache configuration. You need to look into that first.
If it works, add the following line before the RewriteRule to allow serving other files:
The END flag is available since Apache 2.3.9.
You may be on the right track. However, it sounds like your .htaccess file is not being executed. Just because a module is activated, does not mean it is available for you in your particular situation.
Here are some steps to solve your issue:
AllowOverride all
instead.One of these should fix it. I would recommend trying between each step so that you can pinpoint where the error occurred. After determining the cause, you may want to go back and restrict some of those AllowOverrides, depending on your needs.
Best of luck!