Forum Moderators: phranque
I am trying to turn this --> newyork.domain.com into this --> testsite.domain.com/index.php?region=245
I have wildcard subdomains setup on my server so you can type in anything like: anywhere.domain.com and get the content of testsite.domain.com so that is working correctly.
I have a text file (map-list.txt)with the contents in this format:
newyork 245
losangeles 246
boston 247
...
Here is the last few lines of httpd.conf
RewriteEngine on
RewriteMap city txt:/home/username/public_html/testsite/map-list.txt
RewriteCond %{HTTP_HOST} ^([^.]+).domain.com$
RewriteRule ^(.*)$ index.php?region=${city:%1¦http://domain.com/nocity.htm}
But it does not change the region when I go to newyork.domain.com
Any direction on this would be appreciated.
Kent
RewriteEngine on
RewriteCond %{HTTP_HOST} ([^\.]+)\.site\.com [NC]
RewriteRule ^profile/([0-9]+)/$ profile.php?id=$1&company=%1 [NC]
# Redirect main page to login page if accessed
RewriteCond %{HTTP_HOST} ^http://(!www.¦(.*))?site.com$
RewriteRule ^(/)?$ /login/ [R]
This code did work at one point, but now it's not. This should get the subdomain string and put it into the PHP variable $_GET['company']; (which it did when I was first setting up my site).
Now it goes to the main page of my site when I enter [companyname.site.com...] instead of redirecting to [companyname.site.com...]
Any ideas on my syntax? I added the "!www." so it wouldn't redirect to the login page if www is present. Also wouldn't redirect when [site.com...] is entered. I have a wildcard subdomain setup on my server and a demo.site.com subdomain which has it's own directory for it's code and stuff though (and it works).
I just need [companyname.site.com...] to redirect to a login page (I also have other backend pages that need to track the $_GET['company'] variable, so it must be able to be passed to all following rules (which it did at one time).
And [site.com...] and [site.com...] should go to my main index.php page which it does.
Thanks in advance for any help, I hope it's a simple syntax fix because I have quite a few rules following the condition.
Also, you cannot back-reference a negative-match pattern, because when the pattern match is resolved as "True", the back-reference will always be empty.
You'll probably need to break the two hostname checks into two separate RewriteConds, one with the NOT
pattern to disable the rule, and the other to create the desired %1 back-reference.
Jim
I managed to get this working, adding multiple conditions to catch www attempts, etc..
The only thing wrong is my %1 variable doesn't get passed through to my following rules anymore. Should I setup an environment variable so it's available to all rules in my htaccess file? I can't find how to do that.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.)site.com$ [NC]
RewriteCond %{HTTP_HOST} !^(.*)\.site.com$ [NC]
RewriteRule ^ [%{HTTP_HOST}%{REQUEST_URI}...] [L,R=301]
RewriteCond %{HTTP_HOST} ^(.*)\.site\.com [NC]
RewriteRule ^profile/([0-9]+)/$ profile.php?id=$1&company=%1 [NC]
RewriteRule ^profile/([0-9]+)/([0-9]+)/$ profile.php?id=$1&nw=$2&company=%1 [NC]
RewriteRule ^profile/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/$
# Redirect main page to login page if accessed
RewriteCond %{HTTP_HOST} !^(www\.)site.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.site.com$
RewriteRule ^(/)?$ /login/ [R]
Do you see anything that catches your eye?
Thanks,
Bryan
RewriteEngine on
RewriteMap city txt:/home/username/public_html/testsite/map-list.txt
RewriteCond %{HTTP_HOST} ^([^.]+)[b]\.d[/b]omai[b]n\.c[/b]om
RewriteRule !^/([^/]+/)*[^.]*\.[^./])?$ /index.php?region=${city:%1¦[b]/nocity.htm} [L][/b]
Note that posting on this forum modifies the pipe characters; Change any/all broken pipes "¦" back to solid pipes before trying to use any of this code.
Jim
Kent,
Sorry, I missed a left parenthese in there, somehow.
RewriteRule !^/([^/]+/)*[b]([[/b]^.]*\.[^./])?$ /index.php?region=${city:%1¦/nocity.htm} [L]
Macho,
The original poster is the owner of a thread, and responses to the owner's posts take priority. In future, please open your own thread (Thanks!).
RewriteConds and back-references in those RewriteConds apply only to the single RewriteRule following those RewriteConds. A useful general construct is:
RewriteCond %{some_var} (some_var_pattern)
RewriteRule some_URL_pattern - [E=uvarname:%1]
RewriteCond %{ENV:uvarname} some_pattern
RewriteRule some_URL_pattern substitution_URL_head_%{ENV:uvarname}_substitution_URL_tail [flags]
Jim
I appreciate your suggestions and assistance. I might have to hire someone to look deeper into this.
Cheers,
Kent
I often suggest trying a dirt-simple rule when folks have never had any working rewriterule in their configuration... something like
RewriteRule ^foo\.html$ http://www.google.com [R=301,L]
So, carrying on that idea, divide and conquer!
Jim
(2) init rewrite engine with requested uri /cgi-sys/php5/cgi-sys/php5/cgi-sys/php5/cgi-sys/php5/cgi-sys/php5/cgi-sys/php5/cgi-sys/php5/cgi-sys/php5/cgi-sys/php5/cgi-sys/php5/favicon.ico
Getting closer though....
Kent