Jump to content

Unable to use htaccess for mod_rewrite


Go to solution Solved by Cbas,

Recommended Posts

I have this website coded in php: http://iioengine.com/

 

MyBB is installed in a subfolder: http://iioengine.com/forums/, it uses an htaccess file to remove the php extension from its page URLs. As an example, this link works: http://iioengine.com/forums/Forum-Box2D

 

I would like to remove the URL extensions from all the non-MyBB parts of my website - to make this page: http://iioengine.com/demos.php, accessible from this link: http://iioengine.com/demos

 

I thought this would be straightforward, but every .htaccess file I have implemented just results in 404 pages for all queries. Here is what I have now:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
</IfModule>

It gives me 404 pages for non-.php queries, but I found that if I add this line:

RewriteRule . /index.php [L]

all non-'.php' requests get forwarded to the homepage... So mod_rewrite is definitely enabled, it's just not working right. Anyone know what the issue could be?

 

If I can get this working, I also need some rules to cut off the extension even if it is in the query (since all of my hyperlinks use extensions). what do I need in my htaccess file to remove the file extension from the URL in all cases? Thanks

Link to comment
https://forums.phpfreaks.com/topic/276802-unable-to-use-htaccess-for-mod_rewrite/
Share on other sites

  • Solution

Figured it out though I don't know how. Nothing worked until I got rid of Wordpress's htaccess file in my primary root (iioengine is hosted in a subfolder of another site that uses WP). But then once I got everything working, I reactivated that htaccess file and everything still worked okay... Here is my final htaccess code for iioengine.com though:

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

## don't touch /forums URIs
RewriteRule ^forums/ - [L,NC]

## 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]
Edited by Cbas
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.