Writing a theme in the style of MVC
-
Hello WordPress community!
I’m tackling a task of writing a theme in the MVC style. The theme I’m working on is inspired by Laravel so a lot of the file and folder structures have been borrowed.
So the issue I’m having is that I need WordPress to edit the .htaccess file from the functions.php file, if that’s possible?
Consider the following url,
https://www.website.com/controller/method/params/
I need WordPress to redirect this url to index.php?url=controller/method/params/
Essentially, everything after “www.website.com/” is the url parameter.I have managed to solve this by manually editing the .htaccess file so that it looks like this
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)$ index.php?url=$1 [L] RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
This seems to work. I can still access files like wp-login.php without the page breaking, and I have access to the url parameter. However, I don’t want to manually change this file.
Is there a way for WordPress to change this for me?
I should add that I’ve tried to do this with the WP_Rewrite object, but failed. Although I managed to add my custom rewrite rule to the object, it didn’t apply to the htaccess.
Help is appreciated.
- The topic ‘Writing a theme in the style of MVC’ is closed to new replies.