Forum Moderators: phranque
www.mydomain.com/index.php?id_pro=111 to www.111.mydomain.com
or
www.mydomain.com/index.php?id_pro=something to www.something.mydomain.com
I think that both are the same, i tried several rules but i cant get it !
this was the last rule i try:
rewriteEngine on
rewriteCond %{HTTP_HOST} ^(.+)\.mydomain\.com [NC]
rewriteCond %{HTTP_HOST) !^www\.
rewriteRule .* index.php?id_pro=%1 [L]
Thanks alot.
If you mean that when you type something.example.com into your browser address bar, that you get redirected and the address in your browser's address bar changes to example.com, then that is not "working fine" -- You must find that redirect and get rid of it before you can use subdomains of your main domain.
Note that we try to always use only the example.com domain in postings here, for many reasons.
I suspect that what you are trying to do here is to internally rewrite the requested URL www.<numbers>.example.com/ to the internal server filepath /index.php?id_pro=<numbers>
It is very important to state the "direction" of the rewrite properly, and to not mix up external redirects and internal rewrites.
However, none of this matters until you get your server to stop redirecting your subdomains to the main domain.
Jim
I suspect that what you are trying to do here is to internally rewrite the requested URL www.<numbers>.example.com/ to the internal server filepath /index.php?id_pro=<numbers>
in fact i will use letters, but actually iam using numbers for the testings, i think that the rules will be the same, correct me if iam wrong.
So, now what i should do ? add the subdomains ? and then ?
Thanks alot !
RewriteEngine on
#
RewriteCond %{REQUEST_URI} !^index\.php$
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.example\.com
RewriteRule .* index.php?id_pro=%2 [L]
Are you sure that is what you want?
Do you really want to rewrite requests for images, external CSS and JavaScript files, robots.txt, sitemap.xml, labels.rdf, w3c/p3p.xml, and everything else to your one script?
If not, your rule will need to be modified to exclude these URLs from being rewritten, or to allow only the URLS you really want to rewrite to be rewritten.
Does the index.php script look at the Request_URI variable or use AcceptPathInfo to determine which "page" to generate? If not, you'll probably need to pass the requested page URL-path to the script as another GET variable.
Jim
[edited by: jdMorgan at 7:09 pm (utc) on Nov. 20, 2008]
You can do it two ways:
A list of URLs to be mapped to the script.
A list of URLs that must NOT be mapped to the script.
Look for common features of these URLs:
Do you want only the "home page" URLs sent tot he script?
Do they start with the same letters?
Do they all contain some sequence of characters?
Are they in the same directory?
Do they not have file extensions?
You use regular expressions to create a pattern to recognize these URLs, and then rewrite any URL that matches that pattern to the script. Or you can rewrite all URLs which DO NOT match the pattern to your script.
Jim
i mean:
value1.example.com = example.com/index.php?var=something1
value2.example.com = example.com/index.php?var=something2
...
The var value goes from the first valor to the twenty valor.
And there is another problem, the script in some cases will recibe another variable, for example:
example.com/index.php?var=something&Anothervar=some
i now how to rewrite a url to do this:
example.com/var/anothervar.htm
But there is something i dont know, how to do it work in this way:
var.example.com/anothervar.htm
Actually i even cant do it in this way whit only one var:
var.example.com
Iam lost, i dont know where i should start, so the better will be that you prentend i dont know nothing.
where i have to do first ?
create the 20 subdomains i suppose, and then ?
THanks alot Morgan, i apology for my english.
whit this rule:
RewriteEngine on
#
RewriteCond %{REQUEST_URI} !^index\.php$
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.example\.com
RewriteRule .* index.php?id_pro=%2 [L]
and i see only text, so i will have to rewrite the urls to the script, so now how i follow ?
thanks a lot
You could try excluding images, multimedia, CSS and JavaScript files, and "system" files. You want to avoid rewriting a URL to your script if you know that your script cannot generate the correct response for that URL. I do not know all the details of your site, so the following is only an example:
RewriteEngine on
#
RewriteCond %{REQUEST_URI} !^/(index\.php¦robots\.txt¦sitemap\.xml¦labels\.rdf¦w3c/p3p\.xml)$
RewriteCond %{REQUEST_URI} !\.(gif¦jpg¦jpeg?¦png¦ico¦css¦js¦avi¦mpe?g¦wav¦wmv¦mp3¦swf¦flv)$
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.example\.com
RewriteRule .* index.php?id_pro=%2 [L]
Important: Replace the broken pipe "¦" characters in the code above with solid pipe characters before use: Posting on this forum modifies the pipe characters. The correct character is an unbroken vertical line, UTF-8 character-code 7C.
Jim
The only problem now is that i cant escape from the index script if i follow a link with another script, so i suppose that i need to add a new rule for a new script.
for example:
example.com/script.php?id_n=value&id_pro=value
RewriteCond %{REQUEST_URI} !^/(index\.php¦robots\.txt¦sitemap\.xml¦labels\.rdf¦w3c/p3p\.xml)$
RewriteCond %{REQUEST_URI} !\.(gif¦jpg¦jpeg?¦png¦ico¦css¦js¦avi¦mpe?g¦wav¦wmv¦mp3¦swf¦flv)$
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.example\.com\([^.]+)
RewriteRule (.*)(.*) script.php?id_n=%2&id_pro=%2 [L]
Maybe something similar ? i dont have any idea how to do it work whit two variables.
Thanks
var.example.com/another_var
Iam tryng to rewrite:
example.com/script.php?id_n=value&id_pro=value
into:
id_pro_value.example.com/id_n_value
Thanks alot
In this rule the "%2" value what it means ? it is a reference to the third line i think but how it works, because if i change the value to a 3 it dosent work. example : "%3"
I need to understand that so i can make a new rule.
Thanks.
it is a RewriteCond backreference to the 2nd grouped pattern in the preceding directives:
[httpd.apache.org...]
in your example, %1 would refer to the "(www\.)?" and %2 would refer to the "([^.]+)" and there is no %3 defined.
RewriteCond %{REQUEST_URI} !^/(index\.php¦robots\.txt¦sitemap\.xml¦labels\.rdf¦w3c/p3p\.xml)$
RewriteCond %{REQUEST_URI} !\.(gif¦jpg¦jpeg?¦png¦ico¦css¦js¦avi¦mpe?g¦wav¦wmv¦mp3¦swf¦flv)$
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.example\.com\([^.]+).html
RewriteRule .* script.php?id_c=%3&id_pro=%2 [L]
So now using value_id_pro.example.com/value_id_c.html should it work, but iam doing something wrong on the rule, a sintax error maybe ?
Thanks alot.
RewriteCond %{REQUEST_URI} !^/(index\.php¦robots\.txt¦sitemap\.xml¦labels\.rdf¦w3c/p3p\.xml)$
RewriteCond %{REQUEST_URI} !\.(gif¦jpg¦jpeg?¦png¦ico¦css¦js¦avi¦mpe?g¦wav¦wmv¦mp3¦swf¦flv)$
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.example\.com/\([^.]+).html
RewriteRule .* script.php?id_c=%3&id_pro=%2 [L]
I suppose that this one is the right, because it concerns:
value_id_pro.example.com"/"value_id_c.html
But still is not working, any ideas ?
I mean that i will be able to rewrite links like this:
some.example.some.com some.example.net ...
But not like this:
some.example.com/some.html example.com/some.html ...
So, i will need a new rule to add ?
Thanks alot.
Iam trying changuing the rule but i cant do it work, for example this:
RewriteEngine on
#
RewriteCond %{REQUEST_URI} !^/(index\.php¦my_script\.php¦robots\.txt¦sitemap\.xml¦labels\.rdf¦w3c/p3p\.xml)$
RewriteCond %{REQUEST_URI} !\.(gif¦jpg¦jpeg?¦png¦ico¦css¦js¦avi¦mpe?g¦wav¦wmv¦mp3¦swf¦flv)$
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.example\.com
RewriteRule (.*)/([^.]+).html$ my_script.php?id_c=$1&id_pro=%2 [L]
So i can do 1.example.com/8.html
Iam mixing some stuff in the last line, its probably that there is the error, but i dont have any idea of how to make the new rule, any clue ?
I saw some rules whit THE_REQUEST, but i cant figure it out, iam new at this.
Thanks.