0

I am trying without success to do the following rewrite.

No matter what URL is entered or the sub-domain, it should always be "processed" by index.php.

Lets say I go to example.domain.com

The URL will reamin the same but the content is the one from index.php

It shouldn't matter if the URL or the subdomain actually exist.

The same for any example:

other.domain.com/something

Should remain the same fro the user, but index.php what is what should be showed.

Trufa
  • 39,971
  • 43
  • 126
  • 190
  • The file index.php exists, it's in the root (site.com/index.php). I want any url entered, with whatever sub-domain, I want the URL to continue as it is, but do display the contents of index.php. Ist that more clear? – Trufa Mar 02 '13 at 22:18
  • Are those sub-domains addon domains in public_html folders? – Felipe Alameda A Mar 02 '13 at 22:25
  • @faa no, if it is possible, I would like it to work with any random sub-domain that is typed in. – Trufa Mar 02 '13 at 22:28

2 Answers2

1

You may try this in one .htaccess file at root directory of the primary domain (site.com):

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}  !index\.php    [NC]
RewriteRule .*              /index.php?    [L]

# If the above rule doesn't work as expected, use this rule instead:
# RewriteRule .*  http://site.com/index.php? [L]    

This should work for wildcard and addon sub-domains hosted in public_html folders.

The rule-set meets all the requirements in the question:

  • "No matter what URL is entered or the sub-domain" redirects everything to http://site.com/index.php

  • "it should always be processed by index.php". Therefore index.php has to exist somewhere and for this answer, in root directory of http://site.com.

  • "but index.php what is what should be showed". Pretty confusing but one OP comment makes it clear: Keep the incoming URL in the address bar. If that's not the case, replace [L] with [R=301,L]

  • Do not pass anything to the script (index.php) in the substitution URL as the OP doesn't mention it.

Felipe Alameda A
  • 11,791
  • 3
  • 29
  • 37
  • Ok, I'm pretty sure it might be my fault by not explaining correctlt but this is not what I need. What I need is that no matter what url you type in, you will continue to see that exact url but you will be displayed the content of index.php. Is that better? Please ask for any clarification, thanks for the help BTW! – Trufa Mar 02 '13 at 23:06
  • That's indeed what the rule-set in my answer does as it is: `Keep the incoming URL in the address bar.` – Felipe Alameda A Mar 02 '13 at 23:08
  • Yes but, if I'm not mistake as you say, the subdomains actually have to exist I have to create them ass addons. Can't I make it work for one that don't actually exist? – Trufa Mar 02 '13 at 23:10
  • Those are the `wildcard` sub-domains I mentioned, which don't have to be in public_html folders. That applies only to addon sub-domains. Corrected, replaced `or` with `and`. But give it a try, working with sub-domains it's pretty tricky as they are meaningless inside a server. – Felipe Alameda A Mar 02 '13 at 23:14
  • Sorry, but then I don't understand what I'm supposed to do to make it work, I just looked up wildcard subdomains and I went to my cpanel and created a subdomain `*` but I'm not sure that's what I was supposed to do since it's not the expected result. – Trufa Mar 02 '13 at 23:24
  • Check [this link](http://stackoverflow.com/questions/586129/create-subdomains-on-the-fly-with-htaccess-php) for how to create them. – Felipe Alameda A Mar 02 '13 at 23:28
  • Thanks! I'll take a look tomorrow, I can't today... Thanks for all the help! +1 – Trufa Mar 02 '13 at 23:33
  • Let me know how it goes anyway. – Felipe Alameda A Mar 02 '13 at 23:35
0

You could use the following lines in your .htaccess:

RewriteEngine on
RewriteRule ^([^/\.]+)/?$ index.php [L]
Henry van Megen
  • 2,159
  • 2
  • 23
  • 35
  • This wont work since what I'm trying to accomplish is independent of whether the subdomain exists or not... – Trufa Mar 02 '13 at 20:11