Reputation: 93
I am working for a blog system using PHP PDO. I have created a post.php page in my root folder. In the same root, I have an Admin folder. I am getting posts from databases like -
example.com/cat_slug/post_slug
i.e
example.com/php/how-to-learn-php
As you can see there is no post keyword in the URL because of the .htaccess file.
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ post.php?cat=$1&postSlug=$2 [L]
It's correct according to my need but in the same folder, I have the Admin folder(where post.php is located ). The Admin folder contains folders and files. Now, when I open the Admin folder it's going to post.php
like -
example.com/Admin
and it's going to example.com/Admin and output - undefine - slug ad cat. I want to that when I visit the Admin folder it should open Admin files not redirect to the post.php file. I have many folders in my root same as Admin. All are going to post.php execution.
Upvotes: 1
Views: 802
Reputation: 46
Try something like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)$ post.php?cat=$1&postSlug=$2 [L]
Upvotes: 3