Different lighttpd rewrite rules in subirectory - wordpress

I'm having a few issues getting rewrite rules for a specific subdirectroy (different from the webroot) and I'm at a loss as to where to put them.
/var/www/ (webroot containing WordPress)
/var/www/subdirectory (containing other app which requires it's own rewrite rules)
The below rules I for WordPress which is in the webroot dir (/var/www, or http://mywebsite.com):
$HTTP["host"] =~ "mywebsite.com" {
url.rewrite-final = (
# Exclude some directories from rewriting
"^/(wp-admin|wp-includes|wp-content|gallery2)/(.*)" => "$0",
# Exclude .php files at root from rewriting
"^/(.*.php)" => "$0",
# Handle permalinks and feeds
"^/(.*)$" => "/index.php/$1"
)
}
Then I have a second app that sits in a subdirectory of the webroot (/var/www/subdirectory, or http://mywebsite.com/subdirectory) with the following rules:
url.rewrite = (
"(index.php|test.php|favicon.ico)" => "/$1",
"(css|files|img|js)/(.*)" => "/$1/$2",
"^([^\?]*)(\?(.+))?$" => "/index.php?url=$1&$3",
)
What I need is for the 1st set of rewrite rules above applied to everything except the other directories in the #Excluded rule above (as well as /subdirectory) then the 2nd set of rules applied to only /subdirectory
I got the first set of rules for WordPress from a blog somewhere online any may well be not exactly what I need (in regards to matching "mywebsite.com" and could probably be simplified).
I've Googled myself out trying multiple variations (mostly just stabbing in the dark guided by random forum posts that are slightly related), but I just can't wrap my head round it.
So how would I go about having the 2nd set of rules applied to the subdirectory while maintaining the Wordpress rules for the root?
Note: I have no access to subdomains (that would be too easy).

I am not quite sure what you want to express - I will explain what your current ruleset does.
do not use this, user rewrite-once instead
url.rewrite = (
you keep map any index.php and test.php (even foo-test.php) back to the webroot
"(index.php|test.php|favicon.ico)" => "/$1",
you rewrite any subfolder or files containing css,files,tmp or js in it's url back to the webroot
"(css|files|img|js)/(.*)" => "/$1/$2",
now this matches anything in the your webroot (no subdirs!) and keeps get requests
"^([^\?]*)(\?(.+))?$" => "/index.php?url=$1&$3",
)
Update
This should do it (untested)
url.rewrite-once = (
"^/subdir/(?:index.php|test.php|favicon.ico)" => "$0",
"^/subdir/(?:.+/)?(css|files|img|js)/(.*)" => "/subdir/$1/$2", #update #2
"^/subdir/(?:/(?:.+/))?([^\?]*)(?:\?(.+))?$" => "/subdir/index.php?url=$1&$2",
"^/(wp-admin|wp-includes|wp-content|gallery2)/(.*)" => "$0",
"^/(.*.php)" => "$0",
"^/(.*)$" => "/index.php/$1"
)

Related

Wordpress multisite separate media folders plus a shared media folder?

So, I have moved my wp-content folder (and renamed it), and renamed my uploads folder. I will end up having 60+ sites in this install eventually, and it was rather annoying to look inside "uploads/sites" and just see each one labeled with the site id #, which doesn't tell me anything about which site it belongs to. So I had found a function that allowed me to create new folders for each sub-site. And that's working great and all. But I would also like to have one folder with assets that can be shared across the network, instead of having to upload to the individual sites. In other words, I need BOTH the individual media folders, AND a universal assets folder. I suspect that the code I have for creating the named media folders may interfere somehow, but I'm not sure how to solve that. Any help will be appreciated. Following is my current function (which has been put into a plugin so it's not template-dependent).
Note: I feel like there's a better way to set the baseurl & basedir using the UPLOADS folder defined in config. But I couldn't figure out how to get that to work properly.
add_action('init', 'new_upload_filters');
function new_upload_filters(){
add_filter('upload_dir', 'new_upload_dir');
}
function new_upload_dir( $dirs ) {
$blog = get_current_blog_id();
$site = get_blog_details()->blogname;
$sitestrip = str_replace(' ', '', $site);
$sitespace = strtolower($sitestrip);
$dirs['baseurl'] = network_site_url( WP_CONTENT_URL . '/library' );
$dirs['basedir'] = WP_CONTENT_DIR . '/library';
$dirs['path'] = $dirs['basedir']. '/' . $sitespace;
$dirs['url'] = $dirs['baseurl']. '/' . $sitespace;
return $dirs;
}
This code results in a path for each sub-site of /primary-network-url.com/content-dir/library/blogname, which is great (though I'd still also like to have the images broken out by date within each blogname folder too, but that's less important).
In my mind, the ideal would be to have an item within the Admin/Media area for "Shared Images", like a separate category or something. Be able to upload items to that "shared images" area from the parent site, and then those are also available to the sub-sites (but only able to add or delete those from the super admin).
Is this even reasonably possible?

Integrate Smarty Site with Drupal site

I am currently working on a site which is on smarty based.The name of the site is http://example.com
I built a new folder in the root path and installed droupon (which is a component of drupal for buying or creating any deal) on the folder.The site url is http://example.com/coupon
Now I want to integrate or merge this two sites.So that when a registered user access example.com then he can access the example.com/coupon with his session user id.
But this is the problem.
Is this really possible to pass data from smarty based site (example.com) to drupal site example.com/coupon ?
Please help me.
I would write at module in Drupal that looks at $_SESSION and creates and/or login the user at the Drupal-site. Perhaps the rules module can do that work, but you will probably need to implement a rules-hook to grab the relevant session data as input to the rules component.
Here are a few lines of code that do some of the work but you need to implement hook_menu aswell to register an entrypoint for the integration.
//register user
$passwd = user_password();
$edit = array(
'name' => $_SESSION['username'],
'pass' => $passwd,
'mail' => $_SESSION['email'],
'init' => $_SESSION['email'],
'status' => 1,
'access' => REQUEST_TIME,
);
$uu = drupal_anonymous_user();
$u = user_save($uu, $edit);
//Login
global $user;
$user = user_load($u->uid);
$login_array = array ('name' => $username);
user_login_finalize($login_array);
However, Im not sure this is the best way to go about it. Sharing data in the same session-namespace between 2 different applications will probably lead to errors on both sides. Is it not better to implement the whole site in Drupal from the beginning?

Multi-leveled multi-site on Drupal 7

is there an opportunity to make multi-leveled (by hierarchy) multi-site support within drupal's native multi-site solution?
Here's the example:
--example.com
----yyy.example.com (blocks&content shared between it's parent and the same level domains)
------xxx.yyy.example.com (blocks&content shared between it's parent and the same level domains)
----zzz.example.com
----aaa.example.com
------bbb.aaa.example.com and so on...
thanks.
You have to do each multi site one-by-one, and you have to set different database prefixes for each multi-site (you can change that in sites/{multisite_name}/settings.php). So build your multi-sites like this:
1) Build example.com
2) Build example.com/yyy multi-site site. (with prefix 'prefix_xxx_')
3) Build example.com/xxxyyy multi site site. (with prefix 'prefix_xxxyyy_')
and so on...
After ask your web hosting service admin to redirect:
1) example.com/yyy to yyy.example.com
2) example.com/xxxyyy to xxx.yyy.example.com
and so on...
The shared database tables you should specify manually one-by-one at the sites/{multisite_name}/settings.php file like this:
$db_prefix = array(
'default' => 'prefix_xxx_',
'users' => 'prefix_xxxyyy_',
'sessions' => 'prefix_xxxyyy_',
'role' => 'prefix_xxxyyy_',
'authmap' => 'prefix_xxxyyy_',
'sequences' => 'prefix_xxxyyy_',
);

Rewriting with lighttpd - how to remove file extensions

I would like to use lighttpd's mod_rewrite to allow requests without a specific file extension. For instance, I would like the following mappings to automatically work:
Requesting for "/index" would serve "/index.php".
"/dir/file" => "/dir/file.php"
"/dir/file?args" => /dir/file.php?args"
Can this be easily done with a single rewrite rule for a given extension (e.g. ".php")?
Cassy and natbro got this very nearly right, but as user102008 commented, this erroneously rewrites any directory index. Adding a url.rewrite-once matching anything ending with a '/' seems to make it work.
url.rewrite-once = ( "^(.*)/$" => "$1/" )
url.rewrite-if-not-file = ( "^([^?]*)(\?.*)?$" => "$1.php$2" )
Without having tested it, but you can give it a shot:
url.rewrite-once = (
"^([^?]*)(\?.*)?$" => "$1.php$2",
)
Basically it means
take everything but a question mark
and, if exists, take the question mark and everything following
and you rewrite it to the first part, include the .php and add the last part again.
Again: I haven't tested it yet.
cassie's answer above is just about right. i would suggest dropping the trailing comma and using url-rewrite-if-not-file (available since 1.4.x lighttpd). this lets you serve other files that exist in the same directory without them getting rewritten.
url.rewrite-if-not-file = ( "^([^?]*)(\?.*)?$" => "$1.php$2" )
yes
^(.*).php $1 [L,R,NC,QSA]
that would be for .htaccess in a directory
^/(.*).php http://same.site/$1 [L,R,NC,QSA]
where your domain is 'same.site' because it needs to redirect for the URL to change (as opposed to proxy)

Drupal sharing content between two websites

I am farmiar with building drupal sites but not sure what the best way to implement this scenario. I have two domain names mydomain.com and mydomain2.com. I need to have a conten type with some fields in. i.e.
ContentType
Field - Title
Field - Body
Field - Picture
Field - Price
I want both sites to use the same data for the custom conten type. So you enter the data on one site and it will be updated on both.
mydomain.com will show the follwoing infromation from the content type.
ContentType
Field - Title
Field - Body
Field - Picture
mydomain2.com will show all the data.
mydomain.com and mydomain2.com will have diffent look nd feel. And each domain may use some diffent modules. mydomain2.com will be using ubercart and mydomain.com will not.
Would I use mutlisite here and somehow sharte the tables. Use one instance of drupal and do the rest with theming? Use features and context?
Any help would be apreciated.
After doing some research this may be what I need http://drupal.org/project/domain. A case study can be found at http://drupal.org/node/369398.
Still wondering if there are otherways so not acepting this as the answer yet.
You just need to share tables between the sites.
You can share specific tables (best done in logicaly groups) accross Drupal 7 installs by adding something like this to your settings.php file:
$my_db_users = 'drupal_users.shared_';
$my_db_content = 'drupal_content.shared_';
$databases['default']['default'] = array(
'driver' => 'mysql',
'database' => 'defaultdatabase',
'username' => 'databaseuser',
'password' => 'databasepassword',
'host' => '127.0.0.1',
'port' => 3066,
'prefix' => array(
'default' => 'default_',
'users' => $my_db_users,
'sessions' => $my_db_users,
'role' => $my_db_users,
'authmap' => $my_db_users,
'node' => $my_db_content,
'node_revisions' => $my_db_content,
'node_type' => $my_db_content,
),
'collation' => 'utf8_general_ci',
);
In the above instance, we set variables that point to different databases for certain groups of tables. So in the above example, we need three databases: defaultdatabase, drupal_users, and drupal_content.
Then in the array, we set the default table prefix 'default' => 'default_', and that says: "store all tables, unless otherwise specified, in defaultdatabase and make their table prefix default_." We're also saying: "store all users, sessions, roles, and user-role mappings (authmap) in the database drupal_users with the table prefix shared_." And lastly, we're saying: "store all node types, nodes, and their revisions in the database drupal_content with the table prefix shared_."
With great power comes great responsibility:
You will completely hose your install if you don't keep logical groups of tables together.
What are logical groups of tables? Well, probably any table with the prefix node_ in your current install should probably be moved to the shared database. Most well structured modules (say node_access) will have their table name's prefixed with something logical. Based on your modules, ensure you keep groups of tables in the right place (in the default database for site-specific data, or in another database for shared data.)
Add a little bling:
I did a similar install where the users and roles were shared, but NOT the authmap. To what end?
Well, if you do this, you could have the same users and groups accross a large network of sites while still allowing users different permissions on different sites. On one site you may be an editor, but on another you'd be an author.
The Domain module looks good (although I haven't used it). It may be overkill for your needs.
If you want something very simple you can create a module which sets the global $custom_theme in hook_init() depending on the domain.
For me, if this was a critical portion of the site, I would create a custom module. There are a few guides out there to create node_types through modules. I happen to like this one.
That way, you have a basic structure of your data in a custom table and then can customize the call for displaying the data to either include the price column or not.
Again, some may see this as too much work but if you aren't familiar with Drupal module development, this is a great way to learn. If you are familiar, it should be quick and simple.

Resources