简体   繁体   English

.htaccess文件有一些例外

[英].htaccess file with some exceptions

I need a .htaccess file that follows these rules: 我需要一个符合这些规则的.htaccess文件:

  • all files (and subfolders/subfiles) of the folders images, css, js, admin, fonts should be reachable 应该可以访问文件夹images,css,js,admin,fonts的所有文件(和子文件夹/子文件)
  • urls like bla.com/info should be redirected to bla.com/index.php?p=info 像bla.com/info这样的网址应该重定向到bla.com/index.php?p=info
  • urls like bla.com/products/22 should be redirected to bla.com/index.php?p=products&cat=22 像bla.com/products/22这样的网址应该重定向到bla.com/index.php?p=products&cat=22
  • the url bla.com/products should be redirected to bla.com/index.php?p=products url bla.com/products应重定向到bla.com/index.php?p=products

Can anyone help me with this? 谁能帮我这个? This is what I got so far: 这是我到目前为止所得到的:

Options +FollowSymLinks

RewriteEngine On
RewriteBase /staging/

RewriteRule     ^favicon.ico           favicon.ico         [NC,L]
RewriteRule     ^([A-Za-z0-9-]+)/?$     index.php?p=$1       [NC,L] 

But it only works for the first 2 conditions... 但它只适用于前两个条件......

Thanks!! 谢谢!!

These 2 rules should work for you: 这两条规则应该适合你:

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^([a-z0-9-]+)/?$ index.php?p=$1 [NC,QSA,L]

RewriteRule ^([a-z0-9-]+)/([a-z0-9-]+)/?$ index.php?p=$1&cat=$2 [NC,QSA,L]

Try: 尝试:

Options +FollowSymLinks

RewriteEngine On
RewriteBase /staging/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-]+)(?:/(.*?)/?|)$ index.php?p=$1&cat=$2 [L,QSA]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM