htaccess条件与其他RewriteRule

时间:2017-12-10 08:05:01

标签: regex apache .htaccess mod-rewrite

您好我想设置一个RewriteRule,将url参数检查为http://example.com/admin/bla/foo,例如:

If my url contains 'admin' then use:
RewriteRule ^(.*)$ index.php [L]
else
RewriteRule ^([a-z]{2})/(.*)$ ?lang=$1 [L,QSA]

我试过了:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/?admin$ [OR]
RewriteRule ^(.*)$ index.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]{2})/(.*)$ ?lang=$1 [L,QSA]

感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

您可以在站点根目录中使用这些规则.htaccess:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin(?:/|$) index.php [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]{2})/(.*)$ ?lang=$1 [NC,L,QSA]

这假设admin/目录中没有.htaccess。