0

Good day. I am having a little problem with my .htaccess file. In my website, I have the root directory as "Website" and the admin panel as "Website/backend".

I created the htaccess to direct to "index.php"s in each folder depending on the request. i.e website/about will direct to index.php in root folder and i also want website/admin/dashboard to redirect to index.php inside the backend folder.

The issue is I want the admin folder to be "backend" while the path will be "website/admin" for uniformity in my folder structure. For example, if I want to have a profile.php inside the backend folder but I want the path that will show on the browser to be admin/profile.

I have been having errors with this. It's either I get "object not found" or I get redirected to localhost/dashboard. My question: Is this achievable

This is my folder structure

My website

root_folder

  index.php 

  .htaccess

  backend

      index.php

      profile.php (for admins)

My .htaccess file is shown below


Options -Indexes -Multiviews +FollowSymLinks

RewriteEngine On

#RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(?!admin/)(.+)$ /index.php?u=$1 [NC,QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^/admin(.+)$ /backend/index.php?u=$1 [NC,QSA,L]
</IfModule> 

When I change /admin to /backend or when I create an admin folder with an index.php it also works. However, I want to be abe to access files inside backend folder while the browser is showing "admin" in the url.

Thanks.

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
Korlahwarleh
  • 143
  • 11
  • htaccess uses a relative path starting without a leading slash. Change your pattern `^/admin(.+)$` to `^admin(.+)$` . – Amit Verma Apr 21 '20 at 13:32
  • And perhaps change the order as well - handle the specific rewrite for the `admin/` path first, and the more general stuff after. Then you don’t need to explicitly exclude that path by using `(?!admin/)` any more. – CBroe Apr 21 '20 at 13:51
  • @CBroe, did that. It's still not working. – Korlahwarleh Apr 21 '20 at 13:56
  • Did you fix the mistake with the leading slash as well? If so, then edit the question please, to show what _exactly_ you currently got. And give proper examples of the URLs you are trying to access now. – CBroe Apr 21 '20 at 13:57
  • Yes I did. I still got the same result. It only works if I change the folder name to "admin" – Korlahwarleh Apr 21 '20 at 14:19

0 Answers0