我这里有一个htaccess文件
/en/.htaccess
我想使这个条件(对于public_html中的主要htacces)也适用于子文件夹en
RewriteCond %{THE_REQUEST} /events/eventDetails\.php\?id=(.+)&name=(.+)\sHTTP [NC]
RewriteRule ^ /events/%1/%2? [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^events/([^/]+)/([^/]+)/?$/events/eventDetails.php?id=$1&name=$2 [L]
我的htaccess就是这样开始的.
RewriteEngine on
RewriteBase /en/
RewriteRule ^hot-events/?$ hot-events.php [NC,L]
最后一行将链接正确转换为www.example.com/hot-events
但我也希望它能让第一个条件成功.
我的意思是当有人使用此链接时
https://example.com/en/events/123/abc
它应该通过此文件运行查询
https://example.com/en/events/eventDetails.php?id=123&name=abc
目录结构
root/
├── .htaccess
├── index.php
├── events/
│ └── eventDetails.php
└── en/
├── .htaccess
├── index.php
└── events/
└── eventDetails.php
最佳答案 这是因为您的重写目标不正确.您正在重写/events/eventDetails.php而不是/en/events/eventDetails.php,请尝试:
RewriteEngine on
RewriteBase /en/
RewriteRule ^hot-events/?$ hot-events.php [NC,L]
RewriteCond %{THE_REQUEST} /en/events/eventDetails\.php\?id=([^&]+)&name=(.+)\sHTTP [NC]
RewriteRule ^ /en/events/%1/%2? [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^events/([^/]+)/([^/]+)/?$/en/events/eventDetails.php?id=$1&name=$2 [L]