简体   繁体   中英

htaccess redirect rules don't work

I'm new to htaccess so don't judge me please :). I have the following problem - I'm making a website in my local server /it's apache2/ and the project is located in the www/html/subFolder/MVC. In the MVC folder I have the following structure

MVC
|-- .htaccess
|-- app
||-- bootstrap.php
||-- .htaccess
||-- config
||-- controllers
||-- helpers
||-- libraries
|||-- controller.php
|||-- core.php
||`-- database.php
||-- models
|`-- views
`-- public
|-- .htaccess
|-- css
|-- img
|-- index.php
`-- js

The problem is that I try to make a redirect rule for the public folder. For example when the user try to open MVC/public/test.php /some file that doesn't exist/ it should redirect it to the MVC/public/index.php, but my rule doesn't work Here is my htaccess file in the public folder

<IfModule mod_rewrite.c>
 Options -Multiviews
 RewriteEngine On
 RewriteBase /MVC/public
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>

And here is my htaccess in the root folder

<IfModule>
 RewriteEngine on
 RewriteRule ^& public/ [L]
 RewriteRule (.*) public/$1 [L]
</IfModule>

In the main config for apache I didn't allowed to override my htaccess files. I just add a rule for that O

Options +SymLinksIfOwnerMatch
AllowOverride all

And it's all working now

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM