PHPのページのURLについて、
http://hogehoge.com/hoge.php/test/abcde のように、
ページ名の後ろに「/test~~」といった形で、スラッシュで区切って文字を追記すると、
なぜか http://hogehoge.com/hoge.php のページにアクセスすることができてしまいます。
(ただし、現在地のディレクトリはhogehoge.com/hoge.php/test/abcdeと認識されるからか、
相対指定のディレクトリ表記でCSSや画像を指定している箇所は正常に表示されません)
htmlのページでこのようなURLの書き方をすると404エラーになるのに、
何故phpのページではアクセスできてしまうのでしょうか?
上記のような不正なURLへのアクセスがあった場合、
.htaccessなどで「.php」以降の部分を省いたURLへリダイレクトさせることはできますでしょうか。
できれば、不正なURLは阻止しつつ、GET変数でのパラメータ受け取りは行えるようにしたいです。
【04/11 18:36追記】
サーバーの環境はApache 2.4.20とPHP 7.0.15、PHP 5.6.30です。
ルートディレクトリに設置している.htaccessには、以下の内容を記載しています。
PHP_value default_charset none PHP_value output_handler none <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{THE_REQUEST} ^.*/index.php RewriteRule ^(.*)index.php$ http://www.hogehoge.com/$1 [R=301,L] RewriteCond %{THE_REQUEST} ^.*/index.html RewriteRule ^(.*)index.html$ http://www.hogehoge.com/$1 [R=301,L] RewriteCond %{REQUEST_URI} ^/index.php/.*$ RewriteRule ^(.*)index.php$ http://www.hogehoge.com/ [R=301,L] RewriteCond %{HTTP_HOST} ^hogehoge.com RewriteRule (.*) http://www.hogehoge.com/$1 [R=301,L] ErrorDocument 404 /404.html RewriteCond %{REQUEST_URI} !^/contact/.*$ RewriteCond %{REQUEST_URI} !(.*css$) RewriteCond %{REQUEST_URI} !(.*jpg$) RewriteCond %{REQUEST_URI} !(.*png$) RewriteCond %{REQUEST_URI} !(.*gif$) RewriteCond %{REQUEST_URI} !(.*js$) RewriteCond %{REQUEST_URI} !(.*ttf$) RewriteCond %{REQUEST_URI} !(.*woff$) RewriteCond %{REQUEST_URI} !(.*eot$) RewriteCond %{REQUEST_URI} !(.*otf$) RewriteCond %{HTTPS} on RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R,L] </IfModule> # MIME Type 追加 <IfModule mime_module> AddType text/cache-manifest .appcache AddType image/x-icon .ico AddType image/svg+xml .svg AddType application/x-font-ttf .ttf AddType application/x-font-woff .woff AddType application/x-font-woff2 .woff2 AddType application/x-font-opentype .otf AddType application/vnd.ms-fontobject .eot </IfModule> # ETags(Configure entity tags) を無視する設定 <ifModule mod_headers.c> Header unset ETag </ifModule> FileETag None # Enable Keep-Alive を設定 <IfModule mod_headers.c> Header set Connection keep-alive </IfModule> #圧縮の設定 <ifModule mod_deflate.c> <IfModule mod_filter.c> # 古いブラウザでは無効 BrowserMatch ^Mozilla/4.0[678] no-gzip BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch \bMSIE\s(7|8) !no-gzip !gzip-only-text/html # 画像など圧縮済みのコンテンツは再圧縮しない SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png|ico|eot|woff|woff2)$ no-gzip dont-vary AddOutputFilterByType DEFLATE text/html text/xml text/css text/plain AddOutputFilterByType DEFLATE image/svg+xml application/xhtml+xml application/xml AddOutputFilterByType DEFLATE application/rdf+xml application/rss+xml application/atom+xml AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript application/json AddOutputFilterByType DEFLATE application/x-httpd-php application/x-httpd-fastphp AddOutputFilterByType DEFLATE application/x-font-ttf application/x-font-otf AddOutputFilterByType DEFLATE font/truetype font/opentype </IfModule> </ifModule> #ブラウザキャッシュの設定 <IfModule mod_headers.c> <ifModule mod_expires.c> ExpiresActive on ExpiresDefault "access plus 1 days" # CSS ExpiresByType text/css "access plus 1 days" # RSS ExpiresByType application/atom+xml "access plus 1 hours" ExpiresByType application/rdf+xml "access plus 1 hours" ExpiresByType application/rss+xml "access plus 1 hours" # データはキャッシュさせない ExpiresByType application/json "access plus 0 seconds" ExpiresByType application/ld+json "access plus 0 seconds" ExpiresByType application/schema+json "access plus 0 seconds" ExpiresByType application/vnd.geo+json "access plus 0 seconds" ExpiresByType application/xml "access plus 0 seconds" ExpiresByType text/xml "access plus 0 seconds" # Favicon ExpiresByType image/vnd.microsoft.icon "access plus 1 weeks" ExpiresByType image/x-icon "access plus 1 weeks" # HTML ExpiresByType text/html "access plus 0 seconds" # JavaScript ExpiresByType application/javascript "access plus 1 weeks" ExpiresByType application/x-javascript "access plus 1 weeks" ExpiresByType text/javascript "access plus 1 weeks" # マニフェスト ExpiresByType application/manifest+json "access plus 1 weeks" ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds" ExpiresByType text/cache-manifest "access plus 0 seconds" # 画像や動画 ExpiresByType audio/ogg "access plus 1 weeks" ExpiresByType image/bmp "access plus 1 weeks" ExpiresByType image/gif "access plus 1 weeks" ExpiresByType image/jpeg "access plus 1 weeks" ExpiresByType image/png "access plus 1 weeks" ExpiresByType image/svg+xml "access plus 1 weeks" ExpiresByType image/webp "access plus 1 weeks" ExpiresByType video/mp4 "access plus 1 weeks" ExpiresByType video/ogg "access plus 1 weeks" ExpiresByType video/webm "access plus 1 weeks" # Webフォント # Embedded OpenType (EOT) ExpiresByType application/vnd.ms-fontobject "access plus 1 months" ExpiresByType font/eot "access plus 1 months" # OpenType ExpiresByType font/opentype "access plus 1 months" # TrueType ExpiresByType application/x-font-ttf "access plus 1 months" # Web Open Font Format (WOFF) 1.0 ExpiresByType application/font-woff "access plus 1 months" ExpiresByType application/x-font-woff "access plus 1 months" ExpiresByType font/woff "access plus 1 months" # Web Open Font Format (WOFF) 2.0 ExpiresByType application/font-woff2 "access plus 1 months" # Other ExpiresByType text/x-cross-domain-policy "access plus 1 weeks" </IfModule>
回答2件
あなたの回答
tips
プレビュー