Forum Moderators: phranque

Message Too Old, No Replies

rewritemap and mod php not work

         

powerflash

9:20 pm on Jun 3, 2010 (gmt 0)

10+ Year Member



Hi all,

I need set the rewrite rules on my httpd.conf, this is the code

RewriteEngine on

RewriteMap lowercase int:tolower

# define the map file
RewriteMap vhost txt:/var/www/vhosts/domainname.com/conf/vhost.map

# deal with aliases as above
RewriteCond %{REQUEST_URI} !^/icons/
RewriteCond %{REQUEST_URI} !^/cgi-bin/
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
# this does the file-based remap
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/httpdocs/$1

RewriteCond %{REQUEST_URI} ^/cgi-bin/
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/cgi-bin/$1


and in my vhost.map file I write this

sub1.domainname.com /var/www/vhosts/bloog.it/subdomains/beta
sub2.domainname.com /var/www/vhosts/bloog.it/subdomains/beta
....
....



I restart httpd and rewritemap it work but apache not process thephp files , when I visit url I received a request of download of php files

I added this rewriterules between "ErrorLog" row and "<IfModule mod_userdir.c>" row

g1smd

10:17 pm on Jun 3, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Use the HTTP Live Headers extension for Firefox to see what MIME type those files are delivered with.

It's like you'll need to use AddType or somesuch to your configuration tell the server how to process those files.

powerflash

7:21 pm on Jun 4, 2010 (gmt 0)

10+ Year Member



I tried with http live ext. but it don't see sent requests

jdMorgan

7:30 pm on Jun 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Completely delete your browser cache to avoid seeing stale browser-cached pages and server responses.

While testing, you will need to do this each time you load objects for which your server does not return a 'Cache-Control: "must-revalidate"' header.

If you still don't see request-response pairs, then perhaps you made some changes to Live HTTP Headers's settings, and those changes were incorrect; Out-of-the-box, it shows all browser requests and server responses.

Jim

powerflash

7:38 pm on Jun 4, 2010 (gmt 0)

10+ Year Member



now it work! :)


http://testblog3.beta.domainname.com/

GET / HTTP/1.1
Host: testblog3.beta.domainname.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; it; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 GTB7.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: it-it,it;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Cookie: __utma=144577450.733310012.1274534938.1275595125.1275595770.5; __utmz=144577450.1274534938.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); wp-settings-2=m1%3Do%26m5%3Do%26m6%3Do%26m7%3Dc%26m8%3Do%26m2%3Do%26m0%3Dc; wp-settings-time-2=1275134637; wp-settings-4=m4%3Do%26m1%3Do%26m7%3Do%26m6%3Do%26m5%3Do%26m3%3Do%26m2%3Do%26m8%3Do; wp-settings-time-4=1275226306; wp-settings-time-1=1275232192; wp-settings-1=m10%3Do%26m1%3Do; __utma=31563181.1742254361.1275467841.1275493473.1275497918.5; __utmz=31563181.1275467841.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utma=225634463.1080680390.1275497952.1275497952.1275497952.1; __utmz=225634463.1275497952.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); wp-settings-5=m8%3Dc%26m7%3Dc%26m6%3Dc%26m5%3Do%26m1%3Dc%26m2%3Dc%26m3%3Dc%26m4%3Dc%26m0%3Dc%26m9%3Dc; wp-settings-time-5=1275497981; LThttpwwwbloogit=24nurr069a4lckhtuteo21c503; __utmc=144577450
Authorization: Basic YWRtaW46YWxleGZsYXNo

HTTP/1.1 200 OK
Date: Fri, 04 Jun 2010 19:36:34 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Sat, 29 May 2010 19:27:15 GMT
Etag: "48a01da-1ad-487c09c718ac0"
Accept-Ranges: bytes
Content-Length: 429
Connection: close
Content-Type: application/x-httpd-php

powerflash

8:03 pm on Jun 4, 2010 (gmt 0)

10+ Year Member



I added [T=text/html] in:

RewriteRule ^/(.*)$ %1/httpdocs/$1 [T=text/html]

and now header is:



GET / HTTP/1.1
Host: testblog3.beta.domainname.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; it; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 GTB7.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: it-it,it;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Cookie: __utma=144577450.733310012.1274534938.1275595125.1275595770.5; __utmz=144577450.1274534938.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); wp-settings-2=m1%3Do%26m5%3Do%26m6%3Do%26m7%3Dc%26m8%3Do%26m2%3Do%26m0%3Dc; wp-settings-time-2=1275134637; wp-settings-4=m4%3Do%26m1%3Do%26m7%3Do%26m6%3Do%26m5%3Do%26m3%3Do%26m2%3Do%26m8%3Do; wp-settings-time-4=1275226306; wp-settings-time-1=1275232192; wp-settings-1=m10%3Do%26m1%3Do; __utma=31563181.1742254361.1275467841.1275497918.1275680350.6; __utmz=31563181.1275467841.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utma=225634463.1080680390.1275497952.1275497952.1275497952.1; __utmz=225634463.1275497952.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); wp-settings-5=m8%3Dc%26m7%3Dc%26m6%3Dc%26m5%3Do%26m1%3Dc%26m2%3Dc%26m3%3Dc%26m4%3Dc%26m0%3Dc%26m9%3Dc; wp-settings-time-5=1275497981; __utmb=31563181.3.10.1275680350; __utmc=144577450; LThttpwwwbloogit=24nurr069a4lckhtuteo21c503; __utmc=31563181
Authorization: Basic YWRtaW46YWxleGZsYXNo

HTTP/1.1 200 OK
Date: Fri, 04 Jun 2010 20:00:01 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Sat, 29 May 2010 19:27:15 GMT
Etag: "48a01da-1ad-487c09c718ac0"
Accept-Ranges: bytes
Content-Length: 429
Connection: close
Content-Type: text/html



Now browser know format mime but mod php not process php script and it delivery php code like html output

jdMorgan

9:04 pm on Jun 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Add a "header" directive in the PHP file, and have it write the "Content-Type: text/html" header before it sends anything else to the client.

Jim

powerflash

9:22 pm on Jun 4, 2010 (gmt 0)

10+ Year Member



I added this


<?php

header("Content-Type: text/html");


but not resolve problem

jdMorgan

11:30 pm on Jun 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Right, but did you remove the [T=text/html] flag from your rewriterule?

The 'hook' to enable PHP parsing was originally mis-implemented, using the AddType directive instead of the proper AddHandler directive. As a result, you have to leave the MIME-type alone in the RewriteRule, and send the correct MIME-type header from PHP itself.

Jim

powerflash

8:55 am on Jun 5, 2010 (gmt 0)

10+ Year Member



yes fact but same problema not work

powerflash

8:59 am on Jun 5, 2010 (gmt 0)

10+ Year Member




I quote complete branch


<VirtualHost #*$!.#*$!.xx.#*$!:80>
ServerName domainname.com:80
ServerAlias *.domainname.com
UseCanonicalName Off
SuexecUserGroup domainname.com psacln
DocumentRoot /var/www/vhosts/domainname.com/httpdocs
CustomLog /var/www/vhosts/domainname.com/statistics/logs/
access_log plesklog
ErrorLog /var/www/vhosts/domainname.com/statistics/logs/
error_log

RewriteEngine on

RewriteMap lowercase int:tolower

# define the map file
RewriteMap vhost txt:/var/www/vhosts/domainname.com/conf/
vhost.map

# deal with aliases as above
RewriteCond %{REQUEST_URI} !^/icons/
RewriteCond %{REQUEST_URI} !^/cgi-bin/
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/httpdocs/$1

RewriteCond %{REQUEST_URI} ^/cgi-bin/
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/cgi-bin/$1

<IfModule mod_userdir.c>
UserDir /var/www/vhosts/domainname.com/web_users
</IfModule>
ScriptAlias /cgi-bin/ /var/www/vhosts/domainname.com/cgi-bin/
<IfModule mod_ssl.c>
SSLEngine off
</IfModule>
<Directory /var/www/vhosts/domainname.com/httpdocs>
<IfModule mod_perl.c>
<Files ~ (\.pl$)>
SetHandler perl-script
PerlHandler ModPerl::Registry
Options ExecCGI
allow from all
PerlSendHeader On
</Files>
</IfModule>
<IfModule sapi_apache2.c>
php_admin_flag engine on
php_admin_flag safe_mode off
php_admin_value open_basedir "/var/www/vhosts/
domainname.com/httpdocs:/tmp"
</IfModule>
<IfModule mod_php5.c>
php_admin_flag engine on
php_admin_flag safe_mode off
php_admin_value open_basedir "/var/www/vhosts/
domainname.com/httpdocs:/tmp"
</IfModule>
<IfModule mod_fcgid.c>
<Files ~ (\.fcgi)>
SetHandler fcgid-script
Options +FollowSymLinks +ExecCGI
</Files>
</IfModule>
Options -Includes +ExecCGI
</Directory>
<Directory /var/www/vhosts/domainname.com/web_users>
<IfModule sapi_apache2.c>
php_admin_flag engine off
</IfModule>
<IfModule mod_php5.c>
php_admin_flag engine off
</IfModule>
</Directory>

</VirtualHost>

powerflash

12:22 pm on Jun 5, 2010 (gmt 0)

10+ Year Member



I can resolve if say to apache that he must process html extension like php?

jdMorgan

7:26 pm on Jun 5, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't know... It would probably be faster to try it than to post here and wait for an answer.

What URL are you requesting when you test?
What is the exact "problem" that you are seeing?
It is very hard to guess what is wrong without seeing the details here.

In fact, all I can offer is that

# deal with aliases as above
RewriteCond %{REQUEST_URI} !^/icons/
RewriteCond %{REQUEST_URI} !^/cgi-bin/
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/httpdocs/$1
#
RewriteCond %{REQUEST_URI} ^/cgi-bin/
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/cgi-bin/$1

can be more efficiently-written as

# Deal with aliases as above
# rewrite /cgi-bin/ requests first
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
RewriteCond ${vhost:%1} ^(/.*)$
[i]RewriteRule ^/(cgi-bin/.*)$ %1/cgi-bin/$1 [L][/i]
#
# if not /cgi-bin/, then rewrite all other requests except for /icons/
RewriteCond %{REQUEST_URI} !^/icons/
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
RewriteCond ${vhost:%1} ^(/.*)$
[i]RewriteRule ^/(.*)$ %1/httpdocs/$1 [L][/i]

The difference is changing the rule order so that you do not have to check for "/cgi-bin/" twice, and in using the RewriteRule pattern instead of a RewriteCond %{REQUEST_URI} whenever possible. As documented, none of the rewriteconds in a rule are evaluated unless the RewriteRule pattern matches, so using the RewriteRule pattern should be preferred to using a RewriteCond to look at the requested URI.

As shown, all rules should end in [L] unless you have a specific reason not to do so... The [L] only applies if the entire rule matches and is invoked.

Also, you might be able to do this

RewriteCond ${vhost:${lowercase:%{SERVER_NAME}}} ^(/.*)$

to eliminate one more RewriteCond from each rule. If you test that and it works, please let me know. :)

Unfortunately, none of the above addresses your main problem... :(

Jim

powerflash

9:16 pm on Jun 5, 2010 (gmt 0)

10+ Year Member



you can see this url <snip>

[edited by: jdMorgan at 10:10 pm (utc) on Jun 5, 2010]
[edit reason] No URLs, please. See Terms of Service. [/edit]

powerflash

9:20 pm on Jun 5, 2010 (gmt 0)

10+ Year Member



Now I have


RewriteEngine on
Options Indexes FollowSymlinks Multiviews
RewriteMap lowercase int:tolower
RewriteMap vhost txt:/var/www/vhosts/bloog.it/conf/vhost.map
RewriteCond ${vhost:${lowercase:%{SERVER_NAME}}} ^(/.*)$
RewriteRule ^/(cgi-bin/.*)$ %1/cgi-bin/$1 [L]

RewriteCond %{REQUEST_URI} !^/icons/
RewriteCond ${vhost:${lowercase:%{SERVER_NAME}}} ^(/.*)$
RewriteRule ^/(.*)$ %1/httpdocs/$1 [L]


seems to work as before but remains the problem of header

jdMorgan

3:04 pm on Jun 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And what does the header-generation part of your PHP code look like?

Jim

powerflash

6:43 pm on Jun 7, 2010 (gmt 0)

10+ Year Member



thi is header output tracked from HTTPd header addon


[subdomain.domain.it...]

GET / HTTP/1.1
Host: subdomain.domain.it
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; it; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 GTB7.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: it-it,it;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Cookie: __utma=144577450.733310012.1274534938.1275745406.1275772457.10; __utmz=144577450.1274534938.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); wp-settings-2=m1%3Do%26m5%3Do%26m6%3Do%26m7%3Dc%26m8%3Do%26m2%3Do%26m0%3Dc; wp-settings-time-2=1275134637; wp-settings-4=m4%3Do%26m1%3Do%26m7%3Do%26m6%3Do%26m5%3Do%26m3%3Do%26m2%3Do%26m8%3Do; wp-settings-time-4=1275226306; wp-settings-time-1=1275232192; wp-settings-1=m10%3Do%26m1%3Do; __utma=31563181.1742254361.1275467841.1275747281.1275773773.9; __utmz=31563181.1275467841.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utma=225634463.1080680390.1275497952.1275497952.1275497952.1; __utmz=225634463.1275497952.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); wp-settings-5=m8%3Dc%26m7%3Dc%26m6%3Dc%26m5%3Do%26m1%3Dc%26m2%3Dc%26m3%3Dc%26m4%3Dc%26m0%3Dc%26m9%3Dc; wp-settings-time-5=1275497981; __utmc=31563181; wordpress_logged_in_=admin%7C1275920371%7C8b562b0eeb4ada1583d235c0247ee21d; wordpress_test_cookie=WP+Cookie+check; __utmc=144577450; LThttpwwwbloogit=24nurr069a4lckhtuteo21c503
Authorization: Basic YWRtaW46YWxleGZsYXNo

HTTP/1.1 200 OK
Date: Mon, 07 Jun 2010 18:41:40 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Fri, 04 Jun 2010 21:19:47 GMT
Etag: "48a01da-1d2-4883ae1f122c0"
Accept-Ranges: bytes
Content-Length: 466
Connection: close
Content-Type: application/x-httpd-php

jdMorgan

3:39 pm on Jun 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Again, your PHP code must send the HTTP Content-Type header with a value of "text/html" *before sending anything else* to the client.

Jim

powerflash

6:37 pm on Jun 9, 2010 (gmt 0)

10+ Year Member



Hi,

here the code of index.php file:


<?php

header("Content-Type: text/html");

/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/

/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/

define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require('./wp-blog-header.php');
//var_dump(get_defined_vars());
?>

powerflash

6:39 pm on Jun 9, 2010 (gmt 0)

10+ Year Member



the problem is that mod_php not parsing header() function

jdMorgan

9:56 pm on Jun 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Then you may wish to ask about this in the WebmasterWorld PHP forum -- There are more expert PHP users there than here... :)

Jim