1

私はこのコードを持っています:

Options FollowSymLinks
<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^(.*)$ index.php?url=$1 [L]
</IfModule> 
<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

.htaccess があるフォルダー内にある "public" という名前のディレクトリのみを許可する方法がわかりません。このディレクトリ以外の名前は index.php に転送する必要があります。どうすればそれができますか?

4

2 に答える 2

1

公開ディレクトリRewriteCondを除外するために別のものを追加

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} ^/public(/.*)?$
RewriteRule ^(.*)$ index.php?url=$1 [L]

現在、リダイレクトは/publicディレクトリに対してのみ機能します。urlpublic の下にあるパスの残りの部分だけをurl=subfolder/page.php使用し/public/subfolder/page.phpたい場合

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^public/?(.*)$ index.php?url=$1 [L]
于 2013-08-09T18:46:41.580 に答える
0

これでコードを変更します:

Options +FollowSymLinks -MultiViews
<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule (?!^public(/.*|)$)^(.*)$ index.php?url=$1 [L,NC,R=302]

    ErrorDocument 404 /index.php
</IfModule>
于 2013-08-09T18:50:38.920 に答える