Forum Moderators: phranque

Message Too Old, No Replies

subdomain to folder rewrite adaptation?

Little of help with an existing rewrite rule

         

sergiozambrano

10:43 pm on Apr 1, 2010 (gmt 0)

10+ Year Member



I'm trying to use wp subdomains, a plug-in that relies on wildcard DNS to make your wordpress categories into subdomains.

category.wordpresssite.com/page-if-any
into
wordpresssite.com/category/page-if-any

(Showing the subdomain version in browser if possible)

The problem is, in order to achieve that I have to upgrade the account to fix IP, OR creating a rewrite rule, the Godaddy rep told me today.

I've found the rule at [webmasterworld.com...]

# if requested subdomain is not "www" 
rewriteCond %{HTTP_HOST} !^(www\.)?example\.com [NC]
# and we have not already rewritten this request to the subdomain's subfolder
rewriteCond %{THE_REQUEST} !/folder/.
# extract requested subdomain to %2
rewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.example\.com
# rewrite the request to the subdomain's subfolder
rewriterule (.*) /folder/%2/$1 [L]


but it doesn't work.

I think it's a matter of merging that rule with Wordpres's own:


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress


Thank you in advance

jdMorgan

12:58 am on Apr 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Before any code can be modified, it is necessary to answer a few additional questions.

For the WP pages in subdomains, where are items such as images, CSS files, external JavaScripts located? -- Are they in the subdomain-subfolder, in the top-level directory, or somewhere else? How do you plan to determine (based on the requested URL-path) which of these objects are shared among all subdomains, and which are specific to each subdomain?

How do you plan to handle the per-subdomain robots.txt, sitemap.xml, and other search-engine-robot-related files?

Jim

sergiozambrano

1:31 am on Apr 2, 2010 (gmt 0)

10+ Year Member



Very good questions!
I think I saw a fix for the robots and sitemap plugins years ago. I think all of them support it now, for the MU wordpress version.

All the items for posts will be under the root of the main domain (virtual domain) but this website won't have images so far, other than the ones loaded by the template (css), just text.

JS will be under the root. Css is under the theme. Actually, there's NO real subdomain folder. The WP Subdomains plugin is supposed to manage different css, themes, etc for each subdomain. I wonder if that's one of the funcionalities that won't work without a wilcard DNS :(
This rewrite rule will help SEO, only.

For now, there WON'T be more than 1 post per category/domain, which I could render instead of the category.

e.g.: cars.domain.com will show a single post (domain.com/category/cars/cars-post) and let people coment on that single post. No more posts will be uploaded into that subdomain/category.

jdMorgan

2:58 am on Apr 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One other thing. I believe that your hosting company representative should have told you that you will need a unique IP address AND a rewriterule. Actually, it's not so much the unique IP address as that you need an IP-address-based virtual server instead of a name-based virtual server in order to avoid having to "declare" each new subdomain in the server config file. The two phrases really say the same thing, but from a network versus a hosting-environment viewpoint.

So, do you have an IP-address-based server/unique IP address now? If not, that's the next step, then update your DNS configuration, then modify this .htaccess code. There's no use going through the complexities of the code modifications until the server is ready and you can use it for testing, though.

Jim

sergiozambrano

2:35 pm on Apr 2, 2010 (gmt 0)

10+ Year Member



Are you saying that the rewrite (inside the virtual domain) couldn't make a request for domain.com/category out of category.domain.com ?

Is a little hard to me understand that, since WP rewrites rules are inside EVERY virtual domain's folder (their root) and THEY WORK.

I spoke with another Godaddy's rep, and he ASSURED me that any request like category.domain.com will be processed by domain.com, with its own htaccess inside its root folder.

sergiozambrano

3:29 pm on Apr 2, 2010 (gmt 0)

10+ Year Member



Let me help you help me understand hehe.

As per what you say, I understand that any request to a subdomain not declared on the hosting panel (DNS entry or whatever it does) WON'T even get to rewrite rule?

Would it help if I move the site that needs the redirect to the root and put the one currently at the root of the hosting package inside a virtual domain folder?

Thanks!

jdMorgan

4:11 pm on Apr 3, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry if I confused you.

Any request for any subdomain or "add-on domain" *that is* declared in cPanel will be rewritten directly to its 'private' subdirectory/folder, and will not execute the code in your top-level "main domain" .htaccess file.

In this set up, the usual problems are that all add-on domains and subdomains must be declared in advance (although you can use wildcard subdomains) and that scripts and objects cannot be easily shared between the various subdomains and add-on domains, because they cannot access each others' filespace, and they cannot access any filespace above their own DocumentRoot --as defined by the cPanel-generated config code-- which is their "subfolder."

If your server is name-based, then requests for any subdomain or "add-on domain" *that are not* declared in cPanel won't even resolve to a virtual host -- The server won't know what to do with the request.

Again, all of this is much simpler on an IP-address-based virtual server (unique IP address), because you can then point any domains and subdomains you like to the IP address of the server, and then handle all of them with the same top-level .htaccess file, mapping domains and subdomains into the filespace at will. I've done this enough times that I do not bother accepting jobs like this if the client is unwilling to go with an IP-based virtual server -- it's simply too much bother, very restrictive with regard to 'shared objects,' and therefore just doesn't work very well. Basically, the cPanel is too restrictive and "general" in this situation to be useful, and you'll spend far more time and money on fighting it than you would to change the hosting plan to something more appropriate. Frankly, I never use cPanel for anything, and prefer hosting plans where it is not even available. Nothing against cPanel itself, but it's just not the right tool for this job.

Jim