Jump to content

Unable to use htaccess for mod_rewrite


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

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.