[wp-hackers] URL Rewriting to Subdomain Possible?
nikolov.tmw at gmail.com
Sun Jan 12 11:14:41 UTC 2014
You can sort of do that, but it would be a bit complicated.
The first thing is that the admin would have to create a sub-domain and set
it's directory to be the same as the one where WordPress is located(so for
instance if WordPress is in /home/aaa/public_html/, they would have to
create a sub-domain that points to /home/aaa/public_html/ as well ).
What this would do is that whenever that sub-domain is loaded, you would
see the WordPress installation(also if you go to
sub.example.com/sample-page/ and you already have a page with slug
"sample-page", you would see that page in the sub-domain as well). What
this means is that you would want to re-direct everything that is on the
sub-domain and is not created from your plugin to the main domain - this
way you can avoid confusion, and possible SEO penalties(although
technically there should be no links to the sub-domain, except for the ones
that your plugin creates).
After that, you would have to filter or manually create the links that you
want to be pointed to the sub-domain(if you are using a WordPress function
to get the link - like get_permalink() or get_author_posts_url(), there
should be a filter to which you can hook-in and add the sub-domain).
If you are just going to add the sub-domain to the URL, then all you would
want to do is make a redirect to the sub-domain when the URL on the main
domain is accessed(avoiding duplicate content).
If you are going to have custom structure, you would have to create your
custom rewrite rules(via add_rewrite_rule() for instance) and again check
if the URL is accessed on the sub-domain or the main domain.
In order to figure-out if you're on the main domain or on the sub-domain,
you can do parse_url <http://php.net/parse_url>( home_url() ) - this should
give you an array with one of the elements called "host". You should then
grab the current hostname(most-likely you can grab that from the $_SERVER
variable(you should be able to get it from $_SERVER['HTTP_HOST'] ), compare
the two and figure-out if you're on your sub-domain, on the main domain or
On Sun, Jan 12, 2014 at 12:45 PM, Braydon Fuller <ronin at braydon.com> wrote:
> WordPress rewriting works for everything that goes through index.php and
> matches the path not including the domain. I could be wrong, but I think
> when subdomains are used in multiuser, it switches the blog_id, and
> isn't a part of the rewriting.
> On 01/12/2014 02:34 AM, BenderisGreat wrote:
> > I would like to provide an option in a plugin to allow a rewrite to be
> > redirected to the subdomain of their choice. Aside from creating the
> > subdomain themselves, would they also have to do a manual redirection in
> > htaccess? Or is there a way to use wordpress rewrite rules to redirect
> to a
> > subdomain?
> > --
> > View this message in context:
> > Sent from the Wordpress Hackers mailing list archive at Nabble.com.
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
More information about the wp-hackers