J
J
jekahm2016-07-30 18:30:50
Yii
jekahm, 2016-07-30 18:30:50

Fix .htaccess to not download index.php (in Yii2)?

Good day!
There was a task to make a temporary redirect from the sitename .ru domain to the ru subdomain using htaccess. sitename.com for all but some of the pages (which start with /news ). Made it a trace. way:

RewriteEngine On

AddDefaultCharset UTF-8

php_value upload_max_filesize 20M
php_value post_max_size 25M
php_value memory_limit 256M

RewriteCond %{REQUEST_URI} !^/news.*$
RewriteRule (.*) http://ru.sitename.com/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [L]

Redirects from all pages occur. But when accessing pages starting with /news , the index.php file is downloaded instead of being displayed.
Why might this be happening? And how can this be avoided?
Thanks in advance!
UPD 1
Apache setup:
<Directory /path/to/web/dir/www/sitename.ru/web>
    Options +ExecCGI
    php_admin_value open_basedir "/path/to/web/dir:.:/usr/lib/php:/usr/local/lib/php:/tmp"
    php_admin_flag engine on
</Directory>

<VirtualHost 1.11.11.111:81>
    ServerName sitename.ru
    DocumentRoot /path/to/web/dir/www/sitename.ru/web
    SuexecUserGroup admin admin 
    CustomLog /path/to/httpd-logs/sitename.ru.access.log combined
    ErrorLog /path/to/httpd-logs/sitename.ru.error.log
    ServerAlias www.sitename.ru
    ServerAdmin [email protected]
    ScriptAlias /cgi-bin/ /path/to/web/dir/www/sitename.ru/web/cgi-bin/
    php_admin_value open_basedir "/path/to/web/dir:.:/usr/lib/php:/usr/local/lib/php:/tmp"
    php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -f [email protected]"
    php_admin_value upload_tmp_dir "/path/to/web/dir/mod-tmp"
    php_admin_value session.save_path "/path/to/web/dir/mod-tmp"
    AddType application/x-httpd-php .php .php3 .php4 .php5 .phtml
    AddType application/x-httpd-php-source .phps
    AddHandler php5-script .php
</VirtualHost>

UPD 2
I noticed that the same situation happens with all php files that are in the web directory. To fix this, I added the following to the Apache config. line:
AddHandler php5-script .php
Now php files are processed correctly. But the situation with the /news path remains the same.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly, 2016-07-30
@taliban

I understand that these are two physically different servers?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question