Discussion:
URL Rewriting to Subdomain Possible?
BenderisGreat
2014-01-12 10:34:08 UTC
Permalink
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: http://wordpress-hackers.1065353.n5.nabble.com/URL-Rewriting-to-Subdomain-Possible-tp43180.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
Braydon Fuller
2014-01-12 10:45:19 UTC
Permalink
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.
Post by BenderisGreat
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: http://wordpress-hackers.1065353.n5.nabble.com/URL-Rewriting-to-Subdomain-Possible-tp43180.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Nikola Nikolov
2014-01-12 11:14:41 UTC
Permalink
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
somewhere else.
Post by Braydon Fuller
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.
Post by BenderisGreat
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
Post by BenderisGreat
subdomain?
--
http://wordpress-hackers.1065353.n5.nabble.com/URL-Rewriting-to-Subdomain-Possible-tp43180.html
Post by BenderisGreat
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Abdussamad Abdurrazzaq
2014-01-12 11:49:27 UTC
Permalink
Yes it's very easy. Here I've laid it all out for you:

http://pastie.org/8626111
Post by BenderisGreat
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: http://wordpress-hackers.1065353.n5.nabble.com/URL-Rewriting-to-Subdomain-Possible-tp43180.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Loading...