2016-09-20 132 views
1

尝试从index.php中删除并仅解析到可以工作的子目录名称,但是在对.htaccess文件进行更改后,所有其他页面都会重定向到子目录。
例如:
更改:site.com/subdir/index.phpsite.com/subdir/
但随后site.com/subdir/page?id=4解析site.com/subdir/.htaccess从子目录中删除index.php重定向所有动态页面


的.htaccess:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ $1.php [NC,L] 


RewriteBase /subdir/ 

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

如何使得只有index.php的解决写这个规则/ subdir /而不是该目录内的其他页面?

+0

它位于根目录 – Hezerac

+0

是否有'/子目录/'也可以是任何的.htaccess? – anubhava

+0

'/ subdir /'中没有.htaccess文件 – Hezerac

回答

1

您可以使用网站根目录的.htaccess的规则:

RewriteEngine On 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*/)index\.php[?\s] [NC] 
RewriteRule^%1 [L,R=301,NE] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(.+?)/?$ $1.php [L] 

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

完美。非常感谢你!这是一个很大的帮助! – Hezerac

相关问题