WordPressでパーマリンクを変更するとNot Foundになってしまう現象の対処法

/ WordPress / Comment[0]
パーマリンクを変更するとNot Foundになってしまいました。デフォルトの「?p=」は大丈夫なんですけどねぇ。
色々調べてみたところパーマリンクはapacheのrewrite_moduleというモジュールを利用しているらしいです。
このモジュールが読み込まれていないとパーマリンクが使えないというわけです。

UbuntuServer14.04 Apache2.2の場合


モジュール一覧
# apache2 -M
Loaded Modules:
core_module (static)
log_config_module (static)
logio_module (static)
mpm_prefork_module (static)
http_module (static)
so_module (static)
alias_module (shared)
auth_basic_module (shared)
authn_file_module (shared)
authz_default_module (shared)
authz_groupfile_module (shared)
authz_host_module (shared)
authz_user_module (shared)
autoindex_module (shared)
cgi_module (shared)
deflate_module (shared)
dir_module (shared)
env_module (shared)
mime_module (shared)
negotiation_module (shared)
php5_module (shared)
reqtimeout_module (shared)
setenvif_module (shared)
status_module (shared)
Syntax OK
rewrite_moduleは見当たりません。


apache2 -Mの際に次の表示が出る場合は/etc/apache2/apache2.confを編集してみてください。
apache2: bad user name ${APACHE_RUN_USER}
/etc/apache2/apache2.conf
# These need to be set in /etc/apache2/envvars
User www-data
Group www-data


httpd.confにLoadModuleでmod_rewrite.soを追加してみます。
# echo "LoadModule rewrite_module modules/mod_rewrite.so" >> /etc/apache2/httpd.conf
# service apache2 restart
Cannot load /etc/apache2/modules/mod_rewrite.so into server:
/etc/apache2/modules/mod_rewrite.so:
cannot open shared object file: No such file or directory

/etc/apache2/modules/mod_rewrite.soは存在しないとのこと。
lsで見てみると/etc/apache2/以下にmodulesディレクトリは存在しないので当たり前。

findしてみたら/etc/apache2/modulesではなく、/usr/lib/apache2/modulesにありました。
# find / -name mod_rewrite.so
/usr/lib/apache2/modules/mod_rewrite.so


というわけでリンクを張ってみます。
# ln -s /usr/lib/apache2/modules/ /etc/apache2/
# service apache2 restart
# apache2 -M | grep rewrite
 rewrite_module (shared)
無事に成功。
WordPressのパーマリンクも有効になりました。

CentOS Apache2.2の場合


  • WordPressの適切なアクセス権設定

  • WordPressは.htaccessへの書き込みが出来ないとパーマリンクが有効にならないようです。
    ダッシュボードでパーマリンク設定時「.htaccess を更新する必要があります。」と表示された場合アクセス権が適切でない可能性があります。
    /var/www以下を見たら権限がrootだったのでapacheに変更しました。
    # chown -R apache /var/www/

  • httpd.confのDirectoryディレクティブにAllowOverride Allと書き込み.htaccessを許可

  • # vi /etc/httpd/conf/httpd.conf
    :
    <Directory "/var/www/html/wordpress">
    AllowOverride All
    </Directory>
    :

    問題なければ再起動後にパーマリンクが有効になります。
    # service httpd restart
関連記事

コメント

:
:
:
:
:
管理人のみ表示を許可