htaccess为单独的文件夹而不打扰主页

时间:2013-09-25 18:04:16

标签: regex wordpress apache .htaccess mod-rewrite

我在http://example.com的rootfolder中安装了wordpress。我创建了名为world http://example.com/world的新文件夹,我需要htaccess单独处理该特定文件夹,是否可能?

我需要用于文件夹世界的htaccess如下。我在rootfolder htaccess中添加了这个,我得到了内部服务器错误,因此我不想打扰根文件夹。

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule (.*)(\/?)$ / [QSA,NC,L]

我的根文件夹htaccess

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

1 个答案:

答案 0 :(得分:1)

使用以下代码替换DOCUMENT_ROOT/.htaccess

# BEGIN WordPress
<IfModule mod_rewrite.c>

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

# don't do anything for /world folder
RewriteRule ^world/ - [L,NC]

RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>
# END WordPress

使用以下代码替换DOCUMENT_ROOT/world/.htaccess

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /world/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ index.php [L]