Codeigniter ルーティングに問題があり、誰かが助けてくれることを願っています。ルーティングはほとんどの部分で正常に機能しますが、サブドメインが関与すると機能しなくなるようです。htaccessに関係していると思いますが、まったくわからないので、誰かが助けてくれることを願っています。
私がこれに行くとmysite.co.uk/a-page/
、期待どおりに動作します。
これに行くと、subdomain.mysite.co.uk
これも機能します(サブドメイン用に別の default_controller がロードされています)。
予想通り誰かがsubdomain.mysite.co.uk/anything
この 404 に行ったら。
ただし、誰かが誤ってsubdomain.mysite.co.uk/a-page/
これにアクセスした場合は、404 にする必要がありますが、そうではありません。代わりに、次の URL に変わります。
http://www.subdomain.mysite.co.uk/index.php?/a-page/
これにより、「a-page」関数がロードされます。404にしたいのですが、奇妙なことに、プロファイラーは上記のURIを取得しません。代わりに、「ページ」であると考えるだけです。
私の設定では、次のものがあります。
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '/';
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
理想的ではないことはわかっていますが、サブドメインのチェックのために、routes.php の下部で次のことを行っています。
if(isset($_SERVER['HTTP_HOST'])){
$currentURL = parse_url('http://' . $_SERVER['HTTP_HOST']);
$urlHostPieces = explode('.', $currentURL['host']);
$subdomainValue = $urlHostPieces[1]; // will either be a genuine value or the domain name
}else{
$subdomainValue = DOMAIN;
}
if($subdomainValue !== DOMAIN){
//is subdomain
$route['default_controller'] = "controller/function/$subdomainValue";
} else{
//everything else
$route['default_controller'] = "controller/home";
}
私は Fabdrol による htaccess を使用していますが、これはグーグルでよく見かけます。ただし、末尾のスラッシュと強制 www のコードを追加しました。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
# this adds trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [R=301,L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
# Forces WWW
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 /index.php
</IfModule>
奇妙なバリエーションを404にする方法はありますか?また、uri_protocol を REQUEST_URI に変更する必要があることもお読みください。
また、uri セグメントをチェックすることも考えました。存在する場合は404だけですが、それでもセグメントは存在しません。CIに関する限り、余分な文字列が存在しないかのようです。
何も見逃していないことを願っています。さらにサンプルコードが必要な場合は、遠慮なく言ってください。
読んでくれてありがとう。誰かが助けて、なぜこれが起こっているのか説明してくれることを願っています.