RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-/_]+)/?$ index.php?id=$1 [L,QSA]
以上我在我的htacces文件中将directory/page
重写为index.php?id=directory/page
这很好。
我还希望能够添加以下内容:
domain.com/sections/page
重写为index.php?section=1&id=page
domain.com/sections/page2
重写为index.php?section=1&id=page2
domain.com/page
重写为index.php?id=page
每个页面的ID会有所不同
答案 0 :(得分:2)
您必须查看RewriteCond和RewriteRule指令。
根据您的修改,这是一个示例.htaccess
。
RewriteEngine On
# This will process the /sections/(.*) requests, ?section=1 will be appended to query string
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^sections\/(.*)?$ index.php?section=1&id=$1 [L,QSA]
# This will process the other requests, as it does now.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-/_]+)/?$ index.php?id=$1 [L,QSA]