htaccess direct all pages and sub directories to index.php - .htaccess

I'm attempting to get all of the sub directories inside a specific sub directory to load via the index.php file of said directory via its htaccess file. I'm having an issue setting up my .htaccess file correctly.
Directory Path: sitename.com/BLOG/CMS/
My router loads everything to the index.php file in the BLOG directory which is also where its .htaccess file is too, separate from the root sites .htaccess file.
It works for redirecting all of the pages in the blog directory, and any page with a "slug" in it on the CMS directory, like sitename.com/BLOG/CMS/home, but when I go to .com/BLOG/CMS/ in the address bar, with no "slug", it loads the root sites index.php file.
How can I set up my .htaccess file to properly load the BLOG index.php file when visiting .com/BLOG/CMS/ ?
.htaccess for BLOG directory
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [NC,QSA,L]

Try this.
#Options +FollowSymLinks
Options -Indexes
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*) index.php [QSA,NC,L]

Related

htaccess root point to subdirectory without showing folder path

I've tried all sorts of ways. I am having trouble redirecting the root .htaccess file to a subdirectory/public file.
Currently, the root redirects to the folder but the path of file shows up in the url.
For example:
website.com/flarum/public should be website.com
...
public_html
-- .htaccess // below
-- flarum
---- public
------.htaccess //default flarum's htaccess
.htaccess
RewriteEngine On
RewriteRule ^$ /flarum/public/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/flarum/public/
RewriteRule ^(.*)$ /flarum/public/$1
right now it is showing, website.com/flarum/public where it should be website.com

ERR_TOO_MANY_REDIRECTS with two .htaccess and a folder /public

I have a problem with my .htaccess. My redirections work fine on my machine (localhost), but when i upload my site on my server, the first page works but after being redirect many times, but when i click on links, i have a ERR_TOO_MANY_REDIRECTS message.
My folders are organized like that :
.htaccess (1)
/public
.htaccess (2)
index.php
This is my fist htaccess (1)
RewriteEngine On
RewriteRule ^(.*) /public/$1 [L]
This is my second htaccess (2)
Options -MultiViews
RewriteEngine On
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
Problem solved,
The problem wasn't with the .htacess file, but with the function file_exists who take care about uppercase on my server but not on my machine.

How to Remove index.php from URL in PHP

I want to remove index.php from url but so far i couldn't succeed it. I'm using Wamp server on my local and Apache on remote server..
In local root directory, my project files are located in a subfolder like
www/project/index.php
I can access web pages like
localhost/project/index.php/home
localhost/project/index.php/messages/?mId=3
I just want to access it like
localhost/project/home
localhost/project/messages/?mId=3
I already tried some .htaccess rewrite rule but couldnt make it.
Here's how you need to organize:
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [NC,QSA,L]
</ifModule>
And then you will have everything as you need.
You will want to use url rewriting with a .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
Put a .htaccess with this content in each subfolder.

htaccess not working in subdirectory

Hi I have an admin folder that has pretty much the same custom system as my root folder so I need htaccess to make the URL's look nice so in root I have:
example.com/home and admin should be example.com/admin/home.
My root's htaccess is
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?p=$1 [QSA,L]
This works fine but no matter what I do when I have a copy of this in the admin folder it does not work. I have tried RewriteBase I have tried doing the admin folder from the root htaccess but anything I try always makes the pages 404 or 500 error.
Admin htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteBase /admin/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?p=$1 [QSA,L]
Are you sure that you have set properly admin folder's AllowOverride directive? You can set that in your site's configuration file.

.htaccess remove subdirectory from URL

I can't seem to figure this out, I have a directory structure in my root folder like '/state/page--city'. In my htaccess file i redirect all requests that are not directories or files in my root folder to a page.php. So what I would want is to remove the '/state' part from the URL when the users access 'http://example.com/state/page--city/' so that the URL looks like 'http://example.com/page--city/'. Any ideas? Thnx.
.htaccess file:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* page.php?&[|]v1||%{REQUEST_URI}[|]v2||-[|]v3||%{HTTP_HOST}[|]v4||%{REQUEST_FILENAME}[|]v5||EOL[~|~]= [QSA,L]

Resources