2

I'm building a plugin for a WordPress Multisite, and each subsite needs an SEO friendly URL for various tabs that actually appear on the same page.

I have already written the system that detects the correct URL and shows the relevant tab using a query string, but I want to do it without a query string... here's what I mean:

Currently:
http://domain.com/subsite/?tab=contact
Will load the home page of the sub-site, but containing the content of the "Contact" tab. i.e.

if (isset($_REQUEST['tab'])) {
    $tab = $_REQUEST['tab'];
    // Validate $tab here
    get_template_part('tab', $tab);
}

What I Need:
http://domain.com/subsite/contact
To be invisibly rewritten for ALL subsites so that it ends up showing the same content, by rewriting /subsite/whatever to /subsite/?tab=whatever

Any and all help would be greatly appreciated.

Elliott
  • 21
  • 1
  • I find a little bit hard to understand what you want. The tabs are inside the sites? Why don't you use JavaScript to change the tabs? can you give us a real example? – nunorbatista Dec 05 '14 at 14:50
  • The tabs are in a page, they are not pages themselves, so I am using JS to load the tabs once the page is loaded, but I need to be able to link directly to a tab from the address bar without using the query string. Example: I need domain.com/subsite/contact to load the contact tab on page load WITHOUT javascript so search engines see it, and not the content of the home page. – Elliott Dec 05 '14 at 18:03
  • Can't give real example, the project is under NDA and the site is behind a password wall for development. – Elliott Dec 05 '14 at 18:03
  • To clarify, I don't need assistance loading the content... I need assistance with the URL rewrite. As long as the URL rewrites correctly I can handle the rest. – Elliott Dec 05 '14 at 18:04
  • why don't you use anchors? this way you would have http://domain.com/subsite/#contact, is not enough? I've never been a fan of custom rewrite rules inside wordpress, but something like this should do the trick: Options +FollowSymLinks | RewriteEngine on | RewriteRule /tab/(.*) ?tab=$1 – nunorbatista Dec 05 '14 at 18:56
  • Anchors are client-side, PHP can't pick up on them, and it's PHP which decides which tab to load on page load... after that it is done with AJAX... but it's the initial page load I need to control... and anchors aren't SEO friendly either. I am hoping someone can let me know how to do it using the WordPress API and wp_rewrite so that resavign permalinks doesn't overwrite my changes. – Elliott Dec 06 '14 at 13:21
  • http://stackoverflow.com/questions/25063087/wordpress-htaccess-rewrite-url/25063282#25063282 – David Dec 06 '14 at 19:26
  • You might be best looking into this page to see how wordpress and .htaccess handles the friendly urls http://www.martic.net/blog/development/programming/how-does-wordpress-handle-friendly-urls/ – Sam Miller Dec 08 '14 at 23:02

1 Answers1

0

I'm not going to judge your methods as others as I know nothing about your project.

To achieve what you need, use mod_rewrite rule like this:

RewriteEngine On
RewriteRule ^subsite/(.+)$ /subsite/?tab=$1
Kamil Šrot
  • 2,141
  • 17
  • 19