.htaccess问题:404索引

时间:2014-09-19 08:32:55

标签: php regex apache .htaccess mod-rewrite

这是.htaccess ...

中的sub-folder个文件
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteRule (.*) ./index.php?id=$1 [L]
</IfModule>

我希望mydomain.com/sub-folder/string由index.php处理为mydomain.com/sub-folder/?id=string

但我得到404 ......不知道为什么。这是我的根.htaccess

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

1 个答案:

答案 0 :(得分:1)

将你的root .htaccess保留为:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^(index\.php|sub-folder(/.*)?)$ - [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress

并将其保留在/sub-folder/.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /sub-folder/

RewriteRule ^index\.php$ - [L,NC]
RewriteRule (.+) index.php?id=$1 [L,QSA]
</IfModule>