2017-09-06 12 views
0

デフォルトでは。 CodeigniterのURLにはすべてのURLにindex.phpがあり、その後にアンダースコアを使用します。URLをindex.phpでindex.phpにリダイレクトし、文字をハイフンでハイフン(.htaccess)

私の設定は今すぐです。

in Routes.php私は$route['translate_uri_dashes'] = TRUE;を設定しました。つまり、example.some_pathを入力しようとすると、example.some-pathに行きます。

私のcongfig.phpにあります。

$config['index_page'] = '';// remove'index.php'; 

私の.htaccess今

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

# Don't listing directory 
Options -Indexes 
ErrorDocument 403 http://example/404 

# Origin setting 
SetEnvIf Origin "http(s)?://(.+\.)?example\.com(:\d{1,5})?$" CORS=$0 

Header set Access-Control-Allow-Origin "%{CORS}e" env=CORS 
Header merge Vary "Origin" 

問題。

1)はい、example.comまたはexample.com/somepath(index.phpなし)が動作しています。しかし、example.com/index.phpやexample.com/index.php/somepathも利用でき、動作しています。訪問者がrobots.txtで索引を付けなくてもアクセスすると重複コンテンツエラーになります。どのようにindex.phpでアクセスできないanytingをmaksesureするのですか? .htaccessで? 、アンダースコアを持つすべてのリンクが設定さ$route['translate_uri_dashes'] = TRUE;

2)自動的にダッシュに変換(AND Iは、EX(..)アンダースコアが含まれています自分のサイトにリンクをクリックすると、自動的にindex.phpで挿入します。私はリンク<a href="http://example.com/some_path">my link</a>をクリックしたら、それはに変換されますexample.com/index.php/some-path)。私は私のサイトからリンクフォームをクリックせずにexample.com/some-pathに直接アクセスしてみるとよいでしょう。はい、example.com/some-pathが動作しています。

how to makeure index.phpにアクセスできず、自動的にnon index.phpにリダイレクトされますか?

答えて

0

私のようにweb.configを試してみることができます。 <入力を追加=」<入力= "{REQUEST_FILENAME}" matchTypeは= "IsDirectory" 否定= "true" を追加/>を何

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
    <rewrite> 
     <rules> 
     <rule name="Imported Rule 1" stopProcessing="true"> 
      <match url="^(.*)$" ignoreCase="false" /> 
      <conditions logicalGrouping="MatchAll"> 
       <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
       <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
      </conditions> 
      <action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" /> 
      </rule> 
     </rules> 
    </rewrite> 
     <directoryBrowse enabled="true" /> 
    </system.webServer> 
</configuration> 
+0

:私はたぶん何かの.htaccess のファンの多くはありませんよ{REQUEST_FILENAME} "matchType =" IsFile "negate =" true "/>はどういう意味ですか? –

関連する問題