MyBB Community Forums

Full Version: Remove '.php' using .htaccess
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Ubuntu 14.04LTS 32bit

LAMP

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:


http://stackoverflow.com/questions/40260...h-htaccess

http://stackoverflow.com/questions/19921...od-rewrite

http://stackoverflow.com/questions/15917...h-htaccess

http://stackoverflow.com/questions/13832...7#13832827

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


Does MyBB block this? Or what am I doing wrong.
This works for me in .htaccess but breaks my login. Trying to figure out another way.

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## hide .php extension snippet

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
Add this code to .htaccess:

#RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [QSA,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
thanks this helped me too +1