やりたいこと
・ディレクトリの一部を省略しアクセスする
・ブラウザ表示上のURLは変えない
ブラウザ上の表示URL(例)
example.com/yamada/
example.com/suzuki/profile.jpg
実際にアクセスしているURL
example.com/name/yamada/
example.com/name/suzuki/profile.jpg
やったこと
※ブラウザのキャッシュはきちんと削除しています
htaccess
1RewriteEngine On 2RewriteCond %{REQUEST_FILENAME} !-f 3RewriteCond %{REQUEST_FILENAME} !-d 4RewriteCond %{REQUEST_URL} !^/name/ 5RewriteRule ^(.*)$ /name/$1
① example.com/yamada/ にアクセス
→ ブラウザに表示されるURLが example.com/name/yamada/ となってしまい name が表示されてしまう。ですが内容はきちんと表示されます。
name は表示させないようにしたい。
② example.com/yama/ にアクセス(存在しないフォルダ)
→ Internal Server Errorになってしまい、error.logを見ると以下のようになっていて、
log
1[Sat Jun 06 10:39:55.690590 2020] [core:error] [pid 1398] [client 192.168.10.101:50114] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
'LogLevel debug' debugの状態でlogを見ると、
log
1[Sat Jun 06 11:04:25.664214 2020] [authz_core:debug] [pid 1567] mod_authz_core.c(820): [client 192.168.10.101:50387] AH01626: authorization result of Require all granted: granted 2[Sat Jun 06 11:04:25.664259 2020] [authz_core:debug] [pid 1567] mod_authz_core.c(820): [client 192.168.10.101:50387] AH01626: authorization result of <RequireAny>: granted 3[Sat Jun 06 11:04:25.664728 2020] [core:error] [pid 1567] [client 192.168.10.101:50387] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace. 4[Sat Jun 06 11:04:25.664748 2020] [core:debug] [pid 1567] core.c(3833): [client 192.168.10.101:50387] AH00121: r->uri = /name/name/name/name/name/name/name/name/name/name/yama 5[Sat Jun 06 11:04:25.664762 2020] [core:debug] [pid 1567] core.c(3840): [client 192.168.10.101:50387] AH00122: redirected from r->uri = /name/name/name/name/name/name/name/name/name/yama 6[Sat Jun 06 11:04:25.664775 2020] [core:debug] [pid 1567] core.c(3840): [client 192.168.10.101:50387] AH00122: redirected from r->uri = /name/name/name/name/name/name/name/name/yama 7[Sat Jun 06 11:04:25.664785 2020] [core:debug] [pid 1567] core.c(3840): [client 192.168.10.101:50387] AH00122: redirected from r->uri = /name/name/name/name/name/name/name/yama 8[Sat Jun 06 11:04:25.664795 2020] [core:debug] [pid 1567] core.c(3840): [client 192.168.10.101:50387] AH00122: redirected from r->uri = /name/name/name/name/name/name/yama 9[Sat Jun 06 11:04:25.664805 2020] [core:debug] [pid 1567] core.c(3840): [client 192.168.10.101:50387] AH00122: redirected from r->uri = /name/name/name/name/name/yama 10[Sat Jun 06 11:04:25.664815 2020] [core:debug] [pid 1567] core.c(3840): [client 192.168.10.101:50387] AH00122: redirected from r->uri = /name/name/name/name/yama 11[Sat Jun 06 11:04:25.664829 2020] [core:debug] [pid 1567] core.c(3840): [client 192.168.10.101:50387] AH00122: redirected from r->uri = /name/name/name/yama 12[Sat Jun 06 11:04:25.664842 2020] [core:debug] [pid 1567] core.c(3840): [client 192.168.10.101:50387] AH00122: redirected from r->uri = /name/name/yama 13[Sat Jun 06 11:04:25.664852 2020] [core:debug] [pid 1567] core.c(3840): [client 192.168.10.101:50387] AH00122: redirected from r->uri = /name/yama 14[Sat Jun 06 11:04:25.664861 2020] [core:debug] [pid 1567] core.c(3840): [client 192.168.10.101:50387] AH00122: redirected from r->uri = /yama 15[Sat Jun 06 11:04:25.728630 2020] [authz_core:debug] [pid 1569] mod_authz_core.c(820): [client 192.168.10.101:50388] AH01626: authorization result of Require all granted: granted, referer: http://192.168.10.200/yama 16[Sat Jun 06 11:04:25.728671 2020] [authz_core:debug] [pid 1569] mod_authz_core.c(820): [client 192.168.10.101:50388] AH01626: authorization result of <RequireAny>: granted, referer: http://192.168.10.200/yama 17[Sat Jun 06 11:04:25.729116 2020] [core:error] [pid 1569] [client 192.168.10.101:50388] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://192.168.10.200/yama 18[Sat Jun 06 11:04:25.729131 2020] [core:debug] [pid 1569] core.c(3833): [client 192.168.10.101:50388] AH00121: r->uri = /name/name/name/name/name/name/name/name/name/name/favicon.ico, referer: http://192.168.10.200/yama 19[Sat Jun 06 11:04:25.729141 2020] [core:debug] [pid 1569] core.c(3840): [client 192.168.10.101:50388] AH00122: redirected from r->uri = /name/name/name/name/name/name/name/name/name/favicon.ico, referer: http://192.168.10.200/yama 20[Sat Jun 06 11:04:25.729151 2020] [core:debug] [pid 1569] core.c(3840): [client 192.168.10.101:50388] AH00122: redirected from r->uri = /name/name/name/name/name/name/name/name/favicon.ico, referer: http://192.168.10.200/yama 21[Sat Jun 06 11:04:25.729161 2020] [core:debug] [pid 1569] core.c(3840): [client 192.168.10.101:50388] AH00122: redirected from r->uri = /name/name/name/name/name/name/name/favicon.ico, referer: http://192.168.10.200/yama 22[Sat Jun 06 11:04:25.729171 2020] [core:debug] [pid 1569] core.c(3840): [client 192.168.10.101:50388] AH00122: redirected from r->uri = /name/name/name/name/name/name/favicon.ico, referer: http://192.168.10.200/yama 23[Sat Jun 06 11:04:25.729180 2020] [core:debug] [pid 1569] core.c(3840): [client 192.168.10.101:50388] AH00122: redirected from r->uri = /name/name/name/name/name/favicon.ico, referer: http://192.168.10.200/yama 24[Sat Jun 06 11:04:25.729190 2020] [core:debug] [pid 1569] core.c(3840): [client 192.168.10.101:50388] AH00122: redirected from r->uri = /name/name/name/name/favicon.ico, referer: http://192.168.10.200/yama 25[Sat Jun 06 11:04:25.729199 2020] [core:debug] [pid 1569] core.c(3840): [client 192.168.10.101:50388] AH00122: redirected from r->uri = /name/name/name/favicon.ico, referer: http://192.168.10.200/yama 26[Sat Jun 06 11:04:25.729208 2020] [core:debug] [pid 1569] core.c(3840): [client 192.168.10.101:50388] AH00122: redirected from r->uri = /name/name/favicon.ico, referer: http://192.168.10.200/yama 27[Sat Jun 06 11:04:25.729218 2020] [core:debug] [pid 1569] core.c(3840): [client 192.168.10.101:50388] AH00122: redirected from r->uri = /name/favicon.ico, referer: http://192.168.10.200/yama 28[Sat Jun 06 11:04:25.729227 2020] [core:debug] [pid 1569] core.c(3840): [client 192.168.10.101:50388] AH00122: redirected from r->uri = /favicon.ico, referer: http://192.168.10.200/yama
htaccessで
htaccess
1RewriteCond %{REQUEST_URL} !^/name/
このようにしているのに大量のエラーが発生していて name という文字をつけて繰り返しアクセスを試みていると思われます。(初心者なのでよくわかりませんが...)
htaccessがいけないのかapache2.confの設定がいけないのか分かりませんが、原因がわかる方に教えていただきたいです。
環境
サーバー:Debian Buster with Raspberry Pi Desktop (Oracle VM VirtualBox仮想環境)
apache:2.4.38(Debian)
php:7.3.14
apache2.confの一部です。
<Directory /var/www/> Options FollowSymLinks AllowOverride All Require all granted </Directory>
環境(詳細)
"ブラウザに表示されるURLが example.com/name/yamada/ となってしまう"というのは、あり得ない
と指摘されましたが、どうしても name が表示されてしまいます。
時間のある方は全く同じ環境を再現して頂きたいです。
・用意するもの
- 仮想で動かすソフト(Oracle VM VirtualBox など)
- DebianのISO
・手順
OSインストール完了までは省略します。
難しいことは書きません。以下をコピペで再現できると思います。
ssh
1sudo apt-get update 2sudo apt-get install apache2 3sudo nano /etc/apache2/apache2.conf
編集
<Directory /var/www/> Options FollowSymLinks AllowOverride All Require all granted </Directory>
一番下に追記
LoadModule include_module modules/mod_include.so
Ctrl + O で上書き
Ctrl + X で閉じる
ssh
1sudo cp -r /usr/lib/apache2/modules /etc/apache2/modules 2sudo a2enmod rewrite 3sudo service apache2 restart 4cd /var/www/html 5sudo mkdir name 6cd name 7sudo mkdir yamada 8sudo nano index.html
<p>山田</p>
上書き&閉じる
------設定完了------
同じネットワーク内からブラウザで
http://[IPアドレス]/yamada
にアクセスしても
http://[IPアドレス]/name/yamada
になると思います。
回答3件
あなたの回答
tips
プレビュー