я должен настроить URL http://subdomain.example.com/test
и сделать его способным вызвать реальный файл /my-test-script.php
.проблемы с .htaccess перенаправлением и RewriteRule (с или без RewriteCond)
Я не могу понять, почему следующий код работает:
RewriteEngine On
RewriteBase/
RewriteCond %{REQUEST_URI} ^\/?test\/?$
RewriteRule ^\/?(.*)$ /my-test-script.php [NC,L,QSA]
в то время как это один не работает:
RewriteEngine On
RewriteBase/
RewriteRule ^\/?test\/?$ /my-test-script.php [NC,L,QSA]
Является ли обязательным RewriteCond? Если нет, что я пропущу?
Спасибо!
EDIT: .htaccess
и my-test-script.php
оба в корневом /.
EDIT 2: Смешной обновление: Я вижу, он работает с
RewriteRule test /my-test-script.php [NC,L,QSA]
, но не с
RewriteRule ^test$ /my-test-script.php [NC,L,QSA]
EDIT 3: Я создал скрипт, который показывает $ _GET параметры:
RewriteCond %{REQUEST_URI} !^\/?show\-parameters\.php$
RewriteRule ^(.*)$ /show\-parameters.php?path=$1 [NC,L,QSA]
и когда я называю http://subdomain.example.com/test
я вижу:
Array ([path] => /var/www/html/client/project_name/domain/subdomain/test)
EDIT 4: Вот мой VirtualHost:
<VirtualHost *>
ServerAdmin [email protected]
DocumentRoot /var/www/html
RewriteEngine On
### HTTP: from www to non-www ###
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1$1 [R=301,L]
<Directory /var/www/html>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Order allow,deny
allow from all
RewriteBase/
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName subdomain.example.com
ServerAlias www.subdomain.example.com
DocumentRoot /var/www/html/client/project_name/domain/subdomain
RewriteEngine On
### HTTP: from www to non-www ###
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1$1 [R=301,L]
<Directory /var/www/html/client/project_name/domain/subdomain>
Options -Indexes +FollowSymLinks +Multiviews
AllowOverride All
Order allow,deny
allow from all
RewriteBase/
</Directory>
</VirtualHost>
[РЕШИТЬ] EDIT 5: я просто удалил RewriteBase /
линию из .htaccess и в настоящее время работает следующее правило:
RewriteEngine On
RewriteRule ^\/?test\/?$ /my-test-script.php [NC,L,QSA]
Нет, это не каталог, а .htaccess находится в корне домена. В той же папке 'my-test-script.php' – Fasoeu
Apache/2.4.7. DocumentRoot - это '/ var/www/html/client/project_name/domain/subdomain /' – Fasoeu
Да, они оба находятся в '/ var/www/html/client/project_name/domain/subdomain /' – Fasoeu