php - 对 Htaccess 使用两个规则

标签 php regex apache .htaccess mod-rewrite

该线路正在运行

RewriteRule ^(.*)/(.*)?$ site/$1/pagina.php?pagina=$2 [L]

现在我试图在访问链接/inicio时转到index.php页面。

RewriteRule ^inicio/(.*)?$ site/$1/index.php [L]

由此

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^site/

RewriteRule ^inicio/(.*)?$ site/$1/index.php [NC,L]
RewriteRule ^(.*)/(.*)?$ site/$1/pagina.php?pagina=$2 [L]

.

.

.

当前代码,在 friend @anubhava的帮助下

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_URI} ^/site/ [NC]
RewriteRule ^ - [L]


RewriteRule ^([^/]+)/inicio?$ site/$1/index.php [NC,L,QSA]
RewriteRule ^([^/]+)/noticia/([^/]+)/?$ site/$1/pagina.php?pagina=pag_noticiasVer.php&id=$2 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ site/$1/pagina.php?pagina=$2 [L,QSA]

最佳答案

这样吧:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_URI} ^/site/ [NC]
RewriteRule ^ - [L]

RewriteRule ^inicio/([^/]+)/?$ site/$1/index.php [NC,L,QSA]

RewriteRule ^([^/]+)/([^/]+)/?$ site/$1/pagina.php?pagina=$2 [L,QSA]

RewriteCond 仅适用于下一个 RewriteRule

关于php - 对 Htaccess 使用两个规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25851996/

相关文章:

python - 使用 RegExp 拆分 Telegram 消息

javascript - 阻止用户访问 Apache Tomcat 上托管的资源文件夹中的文件

apache - 如何衡量 linux 中的基准测试

apache - isapi 重定向程序未正确处理 Tomcat 和 IIS 7.0 之间的重定向状态代码 302

php - 使用ajax登录不工作

php - Laravel 类别和性能

javascript - 正则表达式匹配双引号内的每个字符串并包含转义引号

php - 为您的网络应用程序使用 api 的优缺点是什么。

java - Android PHP 应用程序不读取 EditText 输入

mysql - mysql中正则表达式匹配中的十六进制字符