homepage Welcome to WebmasterWorld Guest from 54.205.52.110
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
htaccess Rewrite Rule to remove Wordpress Multisite Subdomain in URL
I want all subdomains to "appear" as if they are the root domain.
calvinmicklefinger




msg:4361201
 10:03 pm on Sep 11, 2011 (gmt 0)

I am creating a Wordpress Multisite with subdomains enabled and would like to "hide" the subdomain name whenever a visitor views a subdomain.

For example, the URL may be:
http://00000.mydomain.com
but I would like it to merely show
http://mydomain.com

The .htaccess file currently shows:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]


What does my rule need to be, and where should I add it?

Many thanks!

 

g1smd




msg:4361206
 10:39 pm on Sep 11, 2011 (gmt 0)

Subdomains are a part of the URL and therefore you can't 'hide' it.

If it isn't in the URL then it isn't a subdomain any more.

lucy24




msg:4361207
 10:42 pm on Sep 11, 2011 (gmt 0)

There's one missing piece of information. So far, we've got a redirect, in which (from the user's POV) the browser address bar shows the without-subdomain version of the name.

But the other essential information is: where does the requested content actually live?

Now, as long as we're here:

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]


What are these two rules intended to do? In English, that is, not in .htaccess-speak. The first rule, combined with its conditions, seems to say "if the user asks for a file or directory that really does exist, stop here and loop through the htaccess again". The second rule seems to say "show everyone, regardless of circumstances, the content of index.php". In both cases I can't help feeling I'm missing part of the story.

calvinmicklefinger




msg:4361374
 1:34 pm on Sep 12, 2011 (gmt 0)

Lucy,

I wish I could explain more, but I am absolutely not a coder. I does wish I wuz.

The htaccess code I show is an exact cut and paste of the complete htaccess specified by the Wordpress setup when I installed the script.

"Where does the requested content actually live?" ... in the subdomain.

More info ... Typical scenario.

(1) User arrives at site, which is ...
http://mydomain.com

(2) User inputs subdomain name into an input box. In my instance, the input box will only accept five digit numeric zip code information. They enter
11111

(3) After submitting numeric information, a plugin redirects the user to a subdomain for that zip code ...
http://11111.mydomain.com
but they only see
http://mydomain.com

(4) If the subdomain for a particular zip code does not exist, then the user is redirected to a "default" zip code subdomain.

I am trying to prevent the user from recognizing that the zip code is a part of the specific addrress.




g1smd,

I do "believe" that the visible URL shown in the address bar can be rewritten to be different from the actual path to the file. If it could not, then Wordpress would not be able to write "pretty" permalinks.



Thanks to both ...
Kirk

g1smd




msg:4361381
 1:42 pm on Sep 12, 2011 (gmt 0)

I do "believe" that the visible URL shown in the address bar can be rewritten to be different from the actual path to the file.
No. This is exactly backwards from what actually happens.

A rewrite does not "make" a URL. URLs are defined in the links on your pages. A URL "exists" as soon as there is a link. The URL exists whether or not there is any resource that could fulfill the request.

The rewrite works only when the URL request arrives at the server after the link is clicked. The rewrite connects the incoming URL request from "out there on the web" to a non-default internal server path "here inside the server".

The rewrite process cannot and does not change the links on the pages of your site. You must alter the script that generates the HTML pages so that it formulates the URLs in links in the manner that you want the user to see them.

I do "believe" that the visible URL shown in the address bar can be rewritten to be different from the actual path to the file. If it could not, then Wordpress would not be able to write "pretty" permalinks.
Yes, you can rewrite a URL request in order to fetch content from a different filepath inside the server.

URLs and filepaths are not at all the same thing. URLs are used "out there" on the web. URLs are defined in the links that people click on. Server filepaths are used "here" inside the server. Inside the server there is no concept of URLs or of subdomains. There are only folders and files.

Unless you very clearly specify what you want to do in terms of both URLs used "out there on the web" and filepaths used "here inside the server" you will never be able to move on from the requirements phase to the coding phase.

So, no more of this "I want to hide a URL" nonsense, and on to clear specifications please.

calvinmicklefinger




msg:4361418
 2:58 pm on Sep 12, 2011 (gmt 0)

So, no more of this "I want to hide a URL" nonsense, and on to clear specifications please.

Obviously I do not understand what you are saying and need help.

Since you clearly know a lot more about coding than I do, can you help me write some specifications that will allow me to accomplish what I want?

lucy24




msg:4361465
 4:39 pm on Sep 12, 2011 (gmt 0)

Do a Forums search for the two words "rewrite" and "redirect". For some reason this has become the Question of the Hour* so you will find it answered over and over again with, ahem, increasing impatience.

Functionally what you want to do is this:

First REDIRECT the user to whatever it is you want their browser's address bar to say-- but only if they have not already been rewritten.

Then REWRITE that same user to the place they will really be going to.

Note that external files such as images and css go by where they think you are (the Redirected location), not by where you really are (the Rewritten location). In your specific case this is probably a good thing, though it can cause much grief. Voice of Experience


* Or maybe it was the question of the decade and was simply on hiatus when I started reading these forums.

calvinmicklefinger




msg:4361583
 8:47 pm on Sep 12, 2011 (gmt 0)

Voice of Experience

LOL ... how I can relate.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved