문제

I am investigating Rewrite Rule of Apache and not using .htaccess but virtual host setting for writing them.

Here I have 2 questions:

  1. I can use "RewriteRule blog_rss.xml blog_rss.php" but cannot use "RewriteRule ^blog_rss.xml$ blog_rss.php", why?

  2. Even the first script is working, it doesn't change to the RSS style what I want. Should I set handler for it with Rewrite Rule?

Thanks for answering this question.

Update: Here is the scripts about rewrite rule.

<Directory />
 <IfModule mod_rewrite.c>
  RewriteEngine On
  ErrorDocument 404 /error/404.php
  RewriteRule ^blog_rss\.xml$ blog_rss.php
 </IfModule>
</Directory>
도움이 되었습니까?

해결책 2

Thanks for answers. For V-host, I found the reason finally.

According to RewriteRule in htaccess vs httpd.conf, the Directory path should be the same as the website base path. For example, if the root directory is /var/www/, the <Directory> should set /var/www/ or it will detect the root path of the server.

다른 팁

No you shouldn't set a handler. Doing so will force the PHP code at blog_rss.php to execute as XML. This would result in the entire file being responded with an XML Mime type, which may present major security issues.

However, in the blog_rss.php file before completing the response you might want to set the response type to that of an RSS file.

blog_rss.php

header('Content-Type: text/xml');

v-host

<Directory />
 <IfModule mod_rewrite.c>
  RewriteEngine On
  ErrorDocument 404 /error/404.php
  RewriteRule ^blog_rss\.xml$ blog_rss.php
 </IfModule>
</Directory>

Resource: electrictoolbox.com

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top