Forum Moderators: phranque
i want to do redirects from a specific subdomain to a existing file like this:
RewriteCond %{HTTP_HOST} ^panel\.domain\.com [NC]
RewriteRule ^folder(/?)$ file1.php [L,QSA]
RewriteCond %{HTTP_HOST} ^panel\.domain\.com [NC]
RewriteRule ^(.*)$ file2.php?x=$1 [L,QSA]
then if i access: [panel.domain.com...]
it must redirect to [domain.com...]
[panel.domain.com...] must go to [domain.com...]
i don't want external redirect
so: RewriteRule ^folder(/?)$ [domain.com...] [L,QSA]
doesn't work
and
RewriteRule ^folder(/?)$ [domain.com...] [P,L,QSA]
redirect with internal proxy works, and doesn't do any external redirects, but because of the use of a proxy, i can't use php sessions
$_SERVER['REMOTE_ADDR'] will be equal to server's IP and not user's IP
is there a way to redirect that panel.domain.com to domain.com/file1.php without external redirects nor internal proxy?
thank you in advance
RewriteCond %{HTTP_HOST} ^panel\.domain\.com [NC]
RewriteRule ^folder/?$ file1.php [L]
#
RewriteCond %{HTTP_HOST} ^panel\.domain\.com [NC]
RewriteCond $1 !^(file1¦file2)\.php$
RewriteRule ^(.*)$ file2.php?x=$1 [QSA,L]
There is no need for the [QSA] (Query String Append) flag on the first rule, since this rule does not add to or change anything in the query string. The default mod_rewrite behaviour in this case is to pass the original query string unchanged.
For your "folder" URLs, you should pick one format or the other -- Either require a trailing slash, or require no trailing slash. Then externally redirect the 'wrong' form to the canonical form. This will prevent problems with duplicate content in search rankings, and encourage canonical inbound links to your pages.
Any external redirects should precede all internal rewrites in your code to avoid exposing internal script paths as URLs to clients.
Jim
that worked very well =)
the QSA flag was there only for testing =P
but there's another problem, maybe is not htaccess related
well, that subdomain panel.domain.com was only for logged in users, but with the rewriterule the session is empty in both file1 and file2.php
when accessing directly the files: [domain.com...] the session is there, but not in the subdomain form
do you know why? maybe the sessions are available only in the domain/subdomain where they were created
anyway, thanks for your help, the redirection works fine =D
URLs and filepaths are very different things, and this is especially evident when using mod_alias or mod_rewrite. Unfortunately, it is a very common error to get these two things mixed up, both in thinking and in coding.
Jim