|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
mod_rewrite with subdomains
In my site, I need to have members.sgfcanada.com/XXXX/admin.php -and- URLXXXX/admin.php both point to URLXXXX. I thought the best method to do this would be using the REQUEST_FILENAME variable, since both of the above filename would point to /home/sgfcana/public_html/members/XXXX/admin.php.
Currently, this is my .htaccess file: Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} ^/home/sgfcana/public_html/d([a-z]*)
RewriteRule ^(.*) URL [QSA,L]
Now, I can go to URL and it works as it should (the correct page shows up). But, when I try to modify the code so it will work inside the members directory, like this: Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} ^/home/sgfcana/public_html/members/([a-z]*)/admin.php
RewriteRule ^(.*) URL [QSA,L]
then it doesn't work properly (returns a 404 error). Also, I want it to instead of being lower-case letters and numbers, I want it instead to be and word character(A-Z, a-z, and _ [underscore]) in between 2 and 8 characters long. Any help would be greatly appreciated, for then maybe I'll understand mod_rewrite once and for all ![]() Last edited by ucahg : March 18th, 2002 at 02:47 PM. |
|
#2
|
|||
|
|||
|
It'd be much more efficient to not use REQUEST_FILENAME because it requires a stat() call. BTW, the default RewriteCond is REQUEST_URI, which can do what you needed.
|
|
#3
|
|||
|
|||
|
That works thanks
![]() But now I ran into another problem. Here is my .htaccess file now: Code:
RewriteEngine On RewriteRule ^(.*)/admin.html backend/admin.php?d=$1 [QSA,L] RewriteRule ^(.*)/admin.png backend/images/admin.png [L] RewriteRule ^((.*)/)?siteadmin.php backend/siteadmin.php [L] RewriteRule ^(.*)/redirect.php backend/redirect.php [L] RewriteRule ^(.*)/(.*) backend/viewfile.php?d=$1&f=$2 I want the first 4 redirects to go through, and if any of them are matched, stop rewriting (with the [L] tag). All files that do not match those 4 rules go onto the last rule. The problem is, if I go to admin.html, I see viewfile.php instead of admin.php (it's rewriting with the last rule). This shouldn't be the case in my understanding of mod_rewrite, for according to the Apache documentation: Quote:
Doesn't that mean if any of the rules are matched, none of the following rules will be carried out? Thanks for your help, |
|
#4
|
|||
|
|||
|
>> if any of them are matched, stop rewriting (with the [L] tag)
Then you don't need to repeat the 2 parameter. Instead, you can specify it to - like so: RewriteRule ^(.*)/admin.png - [L] In addition, when you don't specify a RewriteCond, you'd want to specify a leading / like so: RewriteRule ^/xxx/yyy.ext$ - [L] >> RewriteRule ^(.*)/(.*) backend/viewfile.php?d=$1&f=$2 Not sure what you are you trying to do exactly. Though specifying ^(.*)/(.*) usually is not reliable and it doesn't always work. Also, you should set /full/system/path/to/backend/viewfile.php?d=$1&f=$2 [T=application/x-httpd-php,L] |
![]() |
| Viewing: Dev Shed Forums > System Administration > Apache Development > mod_rewrite with subdomains |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|