这是.htaccess中使用的代码,
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /blog/index.php?a=$1 [NC,L]
我想在特定目录上应用它,我无法应用此规则,但目前它将找不到整个网站的网址重定向到domain/blog/index.php
使用 RewriteCond。当您想要将规则应用于特定条件时。
例如
# Include in the next line all folders to include
RewriteCond %{REQUEST_URI} (folder1|folder2|folder3) [NC]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /blog/index.php?a=$1 [NC,L]
或者相反,通过添加!
# Include in the next line all folders to exclude
RewriteCond %{REQUEST_URI} !(folder1|folder2|folder3) [NC]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /blog/index.php?a=$1 [NC,L]
另外,请记住,在某些情况下,Wordpress对htaccess文件进行了访问
在某些情况下,将自定义内容添加到块可以防止这种情况,但并非总是如此。这取决于正在使用的插件。
## BEGIN - My Custom Redirects
<IfModule mod_rewrite.c>
.....
</IfModule>
## END - My Custom Redirects