Frank Kluytmans
Frank Kluytmans

Reputation: 543

htaccess RewriteRule not working - (404 error) from server

I'm trying to rewrite my URL from this:

http://www.example.com/admin/index.php?id=title

to:

http://www.example.com/admin/title

I'm using this code in my htaccess:

RewriteEngine On
RewriteRule ^([^/]*)\.html$ /admin/index.php?id=$1 [L]

But then when I try out rewritten URL's i get a 404 error from my server. What is the mistake I'm making? The .htaccess is in a subfolder called admin and the rewrite rule should only work for that folder.

Upvotes: 1

Views: 2845

Answers (1)

Prix
Prix

Reputation: 19528

This .htaccess should be placed inside the folder admin that must be inside your root folder:

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /admin/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ index.php?id=$1 [L]

The 2 conditions make sure we are not redirecting an existent file or folder and rule tells we want to extract anything not a / and use as the ID.

The RewriteBase tell us your parent folder is admin and as such we work from there and onwards.

Upvotes: 2

Related Questions