Problem with URL rewriting

Lately i have been using a htaccess code to change my site file names from e.g. localhost/tutorials/rewrite/about.php to localhost/tutorials/rewrite/about/
As you can see i am using my xampp localhost and the htaccess file is located in the rewrite folder

The code used works well. Use request_filename to make sure its not a file or folder first and then do the busniess
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ $1.php [L]

The problem is that when making a link for a page. I have changing it to
The htaccess code did work when i didnt have the first to change the .php to /

RewriteRule ^events/([^/]*)/$ events/?url=$1 [L]
But with the first rule in place my page link which should read <a href=“events/event-namer-tile/”> becomes <a href=“localhost/tutorials/rewrite/localhost/tutorials/rewrite/events/event-name/”>

So each works on there own but breaks when brought together

Any help please


As for your trailing /, IMHO, that’s VERY bad as that is telling your visitor that your request is one level deeper in the file structure than it really is (making relative links miss the requested file by one folder level),

Then, your first mod_rewrite block is not changing the query string so there should be no impact.

Finally, the problem is that you’re also making the new link’s query string into a filename. How is Apache supposed to know whether it’s a file or query string?

Recommendation: Get rid of the trailing / and turn events.php?name=event-name into events?name=event-name.

It’s all simple logic - have a read of the tutorial linked in my signature.