View Full Version : Hiding .php with .htaccess file
I.G.O.T.A.
05-02-2016, 12:31 PM
Is it possible to hide the .php extension in the .htacess file? If so what is the best way to do you?
Thank you,
JJ
Paul M
05-02-2016, 05:59 PM
What do you mean by "hide it" ?
<a href="http://stackoverflow.com/a/8371815/6275228" target="_blank">http://stackoverflow.com/a/8371815/6275228</a>
I don't see why you would want to do that though. If you currently have SEO .htaccess rules in place, it may mess up.
I.G.O.T.A.
05-03-2016, 08:34 AM
What do you mean by "hide it" ?
it would be just forum instead of forum.php
http://stackoverflow.com/a/8371815/6275228
I don't see why you would want to do that though. If you currently have SEO .htaccess rules in place, it may mess up.
I got that all taken care of, but I can't seem to get nothing to work to hide the extension. I can do it on Xenoforo, but not with vB.
In Omnibus
05-03-2016, 09:12 AM
The extension is a function of the browser, not of the software.
I.G.O.T.A.
05-03-2016, 08:49 PM
The extension is a function of the browser, not of the software.
So there is no way to do this?
It is possible, you just have to find the right .htaccess rules to rewrite any requests not containing .php in the URL to its version with .php in it. On top of that you should check if the file exits using another .htaccess rule.
cellarius
05-04-2016, 04:52 AM
This is what I have been using in the past with non vB-sites:
## Internally rewrite extensionless file requests to .php files ##
#
# If the requested URI does not contain a period in the final path-part
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
# and if it does not exist as a directory
RewriteCond %{REQUEST_fileNAME} !-d
# and if it does not exist as a file
RewriteCond %{REQUEST_fileNAME} !-f
# then add .php to get the actual filename
RewriteRule (.*) /$1.php [L]
## Externally redirect clients directly requesting .php page URIs to extensionless URIs
#
# If client request header contains php file extension
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.php\ HTTP
# externally redirect to extensionless URI
RewriteRule ^([^.]+).php$ http://your-domain.com/$1 [R=301,L]
## Force custom error page, since php does not return proper errors after this procedure ("no input file specified")
#
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule ^.+\.php$ /path/to/errorpage.php
Anyway - all of this will not remove the file extensions in vB, i.e. the links in the software will still be .php.
Having this used before: it works, but I would advise against using it. I wouldn't go through the potential trouble just for cosmetic reasons.
Paul M
05-04-2016, 10:35 AM
The question is why do you want to do it ?
There is the option to use "Mod Rewrite Friendly URLs" in vB4, which (obviously) has to be combined with some htaccess rules (supplied) which will basically do what you want (use urls with no .php extension).
I.G.O.T.A.
05-04-2016, 11:55 AM
The question is why do you want to do it ?
There is the option to use "Mod Rewrite Friendly URLs" in vB4, which (obviously) has to be combined with some htaccess rules (supplied) which will basically do what you want (use urls with no .php extension).
We have that working, but the main forum still shows the .php. We've tried to hide with the code we have below and it works for what you see below, but not for the main forum.
# Forum
RewriteRule ^threads/.* showthread.php [QSA]
RewriteRule ^forums/.* forumdisplay.php [QSA]
RewriteRule ^members/.* member.php [QSA]
RewriteRule ^blogs/.* blog.php [QSA]
RewriteRule ^entries/.* entry.php [QSA]
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.