24
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

VirtualHost での mod_rewrite

Last updated at Posted at 2014-05-02

wordpress 動かしてるサーバで次のように書いてみたら動かなかった。
ログを見るに RewriteCond がうまくマッチしてくれない。

<VirtualHost *:80>
    DocumentRoot /var/www/wordpress
    DirectoryIndex index.php
    Options -Indexes
 
 
    <IfModule mod_rewrite.c>
        RewriteEngine On
        #RewriteLog /tmp/rewrite.log
        #RewriteLogLevel 9
        RewriteRule ^index\.php$ - [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]
    </IfModule>
</VirtualHost>

ただしくはこう書き直せば良い。

RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d

追記

このようなカタチのほうがポピュラーらしい。
ngyuki さん、ありがとうございます。

<VirtualHost *:80>
    DocumentRoot /var/www/wordpress
    DirectoryIndex index.php
    Options -Indexes

    <Directory /var/www/wordpress>
        <IfModule mod_rewrite.c>
            RewriteEngine On
            RewriteRule ^index\.php$ - [L]
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule . index.php [L]
        </IfModule>
    </Directory>
</VirtualHost>
24
24
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?