I am working on building a WordPress plugin for a custom WordPress multisite network and have a few files that use URL variables to load information from a second database (not the WordPress database).
In the version built outside of WordPress by navigating to http://website.com/NAME-HERE it would check to see if it is a username in my database, if not check to see if its a group in my database and load the file that corresponds to if its a username or group.
Now I'm totally lost about implementing this into WordPress Multisite. As far as I know plugins can't make .htaccess rewrites? How do I make it work on all the network sites?
If not whats the best way to accomplish this?
Do I need to place my pretty.php & .htaccess rewrites into my root directory and point the pages to the files located in the plugin? If so how does this work with multiple themes?
My only other thought as of yet is maybe this can be accomplished with something like RewriteMap.
At this point I figured my best bet was to reach out to the StackOverflow community for assistance or direction.
.htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(\w.+)$ ./pretty.php?pretty=$1 [QSA]
ErrorDocument 404 /404.php
pretty.php
// First check if passed pretty parameter is a username.
if(checkIfUserByUsername($_GET['pretty']))
{
$_GET['username'] = $_GET['pretty'];
include("USERNAME.php");
// If not a username, check to see if it's an event.
}else if(checkIfStreamByPretty($_GET['pretty'])){
$_GET['id'] = getStreamIdFromPretty($_GET['pretty']);
include("GROUP.php");
}else{
// If it's none, redirect to the 404 page.
include("404.php");
}
I want to provide more context of what I am looking to accomplish, I am creating Page Template files one of which is for profiles and one of which is for groups as you've seen above my .htaccess and pretty.php I am then at the top of the page template file then using
$user_id = getIdFromUsername($_GET['username']);
$_GET['user_id'] = $user_id;
I'm really struggling with figuring out how to go about this in a way that allows it to work with multiple themes. Just looking for any sort of solution at this point.
.htaccessyou could checkout other plugins that do make edits to the.htaccessfile, such asAll In One WP Security & Firewall. - Will B.