MyBB Community Forums

Full Version: No login when site uses htaccess to eliminate .php in url
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have been using an htaccess file to eliminate the need for .php in url's.  However, it also prevents login to mybb...here is the htaccess file contents. The rest of the site www.gbarc.ca works fine, no .php is needed in links or other url's.  MyBB is in a different directory than the root, /ForumBB
thanks

#https://newbedev.com/remove-php-from-url# site this code came from
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# For LocalHost !.php
RewriteCond %{HTTP_HOST} !=localhost
RewriteCond %{HTTP_HOST} !=127.0.0.1
RewriteCond %{REMOTE_ADDR} !=127.0.0.1
RewriteCond %{REMOTE_ADDR} !=::1

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

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
It will probably be because you're redirecting to a new URL which will lose the HTTP post data. Other functionality like posting and really anything with a form submission will break.

What is the reasoning for wanting to remove .php from the URL? I doubt many people notice or care what's in the URL. All the URLs in MyBB will have .php in them so it will have to constantly be redirecting, it will be far more hassle than it's worth for whatever you're trying to achieve.
The concept works fine on the sites main page, and there are forms as well which are not broken. It is only MyBB in the subdirectory that is affected. And the url looks better and is easier for users to follow...for example instead of gbarc.ca/contact.php it is now gbarc.ca/contact. MyBB itself does not require you to enter .php to run the software, but it does to login. I hope there is a solution
Again, I think the issue is that you're forcing a redirect. The form action is going to /member.php, you then redirect it to /member, so it loses the post data. The htaccess rules seem to be disabled currently, but if you enable them again, you'd see this redirect in the browser developer tools network tab. You can try changing the 302 redirect to a 307 to see if that retains the post data.
Would this post be of any help
https://community.mybb.com/thread-77141.html
No, that's just redirecting away from index.php, so domain.com/index.php becomes domain.com. You're trying to remove parts of the URL which is a different thing entirely, and index.php doesn't receive post data like member.php and other files do. Did you try changing the 302 redirect to be a 307?