2017-01-04 6 views
0

私はニュースを含めるためにアドオン(CMS用)に取り組んでいます。多くのインデックス・ファイルを作成しないようにするには、私はhtaccessファイルにリダイレクトを使用しようとしましたが、私がルートディレクトリにCMSのための.htaccessファイルを使用している私;-)サブフォルダをファイルにルーティングする

ために複雑であるように思わ:

ErrorDocument 404 404.php 

RewriteEngine On 

# Redirect from http to https 
RewriteCond %{HTTPS} off 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

RewriteCond %{HTTP_HOST} !^domain.tld$ [NC] 
RewriteRule ^(.*)$ https://domain.tld/$1 [L,R=301] 

# If called directly - redirect to short url version 
RewriteCond %{REQUEST_URI} !/page/intro.php 
RewriteCond %{REQUEST_URI} /page 
RewriteRule ^page/(.*)$ /$1 [L,R=301] 

# Send the request to the index.php for processing 
RewriteCond %{REQUEST_URI} !^/(page|backend|framework|include|languages|media|account|search|temp|templates/.*)$ 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([\/\sa-zA-Z0-9._-]+)$ /index.php?$1 [QSA,L] 

# allow robots.txt (all other txt are denied before) 
RewriteCond %{REQUEST_URI} !/robots\.txt$ [nocase] 
RewriteRule \.txt$ - [forbidden,last] 

/page/folder1/accessfile/lorem/ipsum 

と:私はからリダイレクトしたい

--> page/ 
----> folder1/accessfile.php 
----> folder1/.htaccess 

現在の構造/ページ/ folder1の/ accessfile/Loremの/イプサム/#(存在しないフォルダ)

へ:

/page/folder1/accessfile.php 

私はpage/folder1/.htaccessでこれを使用してみましたと思います:

Options +FollowSymLinks 
RewriteEngine On 

RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteCond %{SCRIPT_FILENAME} !-f 

RewriteRule ^accessfile/.*$ ./accessfile.php 

しかし、これはうまくいかない:-(

答えて

0

htaccessファイルをpage/ディレクトリのルートディレクトリに置きます。 htaccessファイルが既に存在する場合は、の前に書き換えルールを入れて# If called directly - redirect to short url version行にします。ここで

は何が必要です:

Options +FollowSymLinks 

<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteBase/

    # Make sure it's not an actula file/dir being accessed 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 

    # Make sure request uri does not contain the actual file 
    # name, avoiding recursive rewrite loops 
    RewriteCond %{REQUEST_URI} !accessfile\.php 
    RewriteRule page/folder1/accessfile/?(.*)? /page/folder1/accessfile.php?q=$1 [R,L,QSA] 
</IfModule> 
## Results 
# page/folder1/accessfile    => page/folder1/accessfile.php?q= 
# page/folder1/accessfile/foo   => page/folder1/accessfile.php?q=foo 
# page/folder1/accessfile/foo/bar  => page/folder1/accessfile.php?q=foo/bar 
# page/folder1/accessfile/foo/bar/baz => page/folder1/accessfile.php?q=foo/bar/baz 

ご覧のとおり、便宜上、書き換えルールは、クエリ文字列パラメータとしてリクエストURIを書き換えます。したがって、PHPファイルは$_GET['q']を使用して渡されたデータにアクセスできます。

クリーンURLを保存して、フードの下のPHPファイルにリクエストを書き直したい場合は、そのRフラグを削除してください。

+0

1つの問題を除いてほぼ完璧に動作します:スラッシュの後ろ.../page/-redirectionの動作を少し変更しました。#要求URIに実際のファイルが含まれていないことを確認してください #名前は再帰的な書き換えループを避けます RewriteCond%{REQUEST_URI}!kurse \ .php RewriteRule folder1/accessfile /?(.*)? /folder1/accessfile.php?q=$1 [L、QSA] RewriteRuleページ/フォルダ1/accessfile /?(.*)?/page /schule-bildung/accessfile.php?q=$1 [L、QSA] '呼び出し** page/folder1/accessfile **は正常に動作しますが、** page/folder1/accessfile/**は正しくリダイレ​​クトされません。 – creativecat

+0

問題を再現できません。 'page/folder1/accessfile'と' page/folder1/accessfile/'(末尾にスラッシュを含む)の両方が' page/folder1/accessfile.php?q = 'にリダイレクトされます。 – sepehr

関連する問題