Forum Moderators: phranque
RewriteEngine on
Options +FollowSymlinks
RewriteCond %{REQUEST_URI}!^/index\.php
RewriteCond %{HTTP_HOST}!^www\.
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com
RewriteRule .* [domain.com...] [nc]
What i want to achieve is that urls of
[variable.domain.com...] will access the page [domain.com...]
However, the address bar should still show [variable.domain.com....]
This script doesnt work... I don't know why. This is the error i get from the page:
------------------
This is the Plesk™ default page
If you see this page it means:
1) hosting for this domain is not configured
or
2) there's no such domain registered in Plesk.
For more information please contact Administrator.
------------------
Please help, I've been researching the net and tried so many but still I failed.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/viewforum\.php$
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule .* http://www.example.com/viewforum.php?f=%1 [L]
Jim
i also created this rewrite rule to redirect from [domain.com...] to [domain.com...] .
RewriteRule ^http://www.domain.com/artist/(.*)$ [domain.com...] [nc]
This one doesn't work too.. any ideas? please help
What URL did you request?
What do you see in your browser screen?
What do you see in the browser address bar?
What do you see in your server access log?
What do you see in your server error log?
And finally, how do the results differ from what you expect? In some cases, it is the expectations that are incorrect, and not the implementation.
Jim
I typed in the address bar:
[band.domain.com...]
and this page should access:
[domain.com...]
--What do you see in your browser screen?
instead i see this error page.
This is the Plesk™ default page
If you see this page it means:
1) hosting for this domain is not configured
or
2) there's no such domain registered in Plesk.
For more information please contact Administrator.
---What do you see in the browser address bar?
[band.domain.com...]
I simply want a way for users to easily manage a redirect on their subdomains?
band.domain.com
points to www.domain.com/viewforum.php?f=band
I know that, cpanel, does this quite well and it is a feature that I require. But im using Plesk
I want to allow the URLs viewforum.php query string variable at the domain's root to be accessed as though they are a subdomain
I'm very sory for i'm a beginer in this mod_rewrite, i also dont know where to access the server and error logs.
:(
I hope this is clear, forgive my english, im chinese.
1) hosting for this domain is not configured
or
2) there's no such domain registered in Plesk.
In order for this to work, three steps are needed:
If step 1 was missing, you would get domain resolution errors, "This host cannot be found" messages. Your code is what you need for step 3. But it sound to me like step 2 is missing; the server does not know what to do with subdomain requests, so your code is never executed.
In order to fix this, you'll probably need to
...please contact Administrator.
Jim
I was able to overide that redirects the subdomain to its default directory by editing the top level vhost.conf.
Now i got a new problem. When I logged in to the site and go to the page using a link or typing the URL of the fake subdomain (http://bandname.domain.com), my session dissapeared. Everytime I go to the page even I am logged in, I was logged out or not totally logged out because when i go back to the page without the subdomain, i was logged in again.
Seems like using the subdomain my session dissapeared but the session is there when i go back to the page without the subdomain.
Is there a way to maintain a single session to multiple subdomain, or is there a solution to fix this issue. Any advice.?
Here is the directory structure of the site when i access it through FTP:
bin
cgi-bin
conf --> root conf where vhost.conf is located
error_docs
etc
httpdocs ---> root folder of the site... and the root of phpbb
lib
pd
private
subdomains ---> empty, no folders and files - default directory of subdomains
tmp
usr
var
web_user
I think the solution to this is to point all my subdomain to the directory root of my domain name. that is on /httpdocs/ directory.
I tried this script in my root vhost.conf but it doesnt work
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteMap lowercase int:tolower
ServerAlias *.domain.com
RewriteCond %{REQUEST_URI}!^/index.php
RewriteCond %{HTTP_HOST}!^www.domain.com$
RewriteCond %{HTTP_HOST}!^webmail\.domain.com$
RewriteCond %{HTTP_HOST} ^[^.]+\.domain.com$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule .* [domain.com...] [P]
RewriteRule ^([^.]+).domain.com(.*) /home/httpd/vhosts/domain.com/httpdocs/$2 [L]
</IfModule>
The session is lost because of the mod rewrite. I guess the reason why is that the subdomain i generated through mod_rewrite still references the subdomain directory not the main domain directory where my session cookies are located.
I'm thinking if there's a way to mod_rewrite the subdomain and will point the sub directories to the root subdomain then it might work.
Again this is what I want to achieve. Changing [bandname.domain.com...] to access the page [domain.com...] without actually changing the URL in the address bar and loosing sessions.
Please help for i've been trying to solve this for more than two weeks already. I'm loosing hope. I'm sure there is a way.
So, this might work better:
ServerAlias *.domain.com
RewriteEngine on
# RewriteMap lowercase int:tolower
RewriteCond %{REQUEST_URI} !^/viewforum\.php$
RewriteCond %{HTTP_HOST} !^(www¦webmail)\.domain\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com
RewriteRule . /viewforum.php?f=%1 [L]
# RewriteRule ^([^.]+).domain.com(.*) /home/httpd/vhosts/domain.com/httpdocs/$2 [L]
I assume that the first RewriteCond was just copied and pasted from an existing code example. The usual intent of this type of construct is to prevent an 'infinite' rewrite loop if the request has already been rewritten to the "page" in the final rewriterule. So I have changed the first RewriteCond from testing for "/index.php" to "/viewforum.php" to prevent such a loop.
In addition, the user-requested "page name" will be discarded (subject to your exclusions), and all requests except for "/viewforum.php" or the pages in the "www" or "webmail" subdomains will be rewritten to "/viewforum.php". I hope that's what you want, but I don't know.
It is possible that your sessions cookie is domain-based. Because you were doing a redirect or proxy throughput, that domain was changing, so the session no longer applied. If the above does not "work better", then you'll need to dig into the logic underlying session tracking to find out what dependencies apply to sessions.
Replace all broken pipe "¦" characters above with solid pipes before use; Posting on this forum modifies them. Flush your browser cache after any change to the code.
Jim
Im so happy that after so many retries I finally found the answers from you. Thank you very much.
Now I still have a problem (we're almost there)
all images, css, all links are now gone.. they are now pointed relative to the subdomain, not to the document root of the domain name... example, images and links are now pointed to [bands.subdomain.com...] not to [domain.com...] I'm thinking to add this script at the end but not sure if this will work.
RewriteRule ^[^.].domain.com /home/httpd/vhosts/domain.com/httpdocs/ [L]
Any solution to this? a rewrite rule maybe? or should i update all links to absolutely map to the document root of the domain name?
please advice. Thank you very much.
What does matter is that there's nothing in the code above that prevents requests for these files from being rewritten to your php script.
So, you may be able to cure this problem simply by excluding these requests from being rewritten by adding something like:
RewriteCond %{REQUEST_URI} !\.(css¦gif¦jpe?g¦png)$
One thing that will help clarify this kind of problem for you is that it is the browser that resolves relative links on your pages to a canonical URL. So, if the browser sees a relative link on a page in one of your 'band' subdomains, it assumes that that link should be canonicalized to that subdomain. Since all of these subdomains actually resolve to the filespace of your main domain, that doesn't really matter, but unless your php script can handle the css and image requests, you won't want to rewrite these requests to the script.
If you want to use canonical links to avoid this problem, you can. On the one hand, the URLs "look better" if they maintain the current subdomain path -- it looks better to the user. On the other hand, if you have any very large images and/or scripts that are used in all subdomains, and if your users tend to browse around in many subdomains, then there would be a small caching-related advantage to using canonical links on those resources, so that the client browser would know that it didn't need to re-fetch them when navigating to a page in a new subdomain.
If you pursue a rewrite solution, be aware that RewriteRule cannot "see" the domain; You must use A RewriteCond testing %{HTTP_HOST} to test it or create a back-reference to it.
Jim
Considering performance, is it better to absolutely path the images or add a rewriteCond instead?
The problem is that all the images doesnt display no more. When I type path/css images on the Adress Bar of the Browser it displays the band main page instead (http://band.domain.com/viewforum.php?f=band).
All images/css are redirected to the main band page when i typed it in the address bar.
What do you suggest, absolutely path the images or add a rewrite condition?
Thank you very much.