我的.htaccess
文件:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
RewriteRule ^([a-zA-Z0-9-]+)$ index.php?page=$1 [QSA,L]
RewriteRule ^([a-zA-Z0-9-]+)/$ index.php?page=$1 [QSA,L]
我在URL中定义了一个键,即“页面”,该键工作正常。现在,我需要包含第二个键,但是每个页面的“键”都会不同。
例如:
example.com/index.php?page=user?id=john
example.com/index.php?page=product?url=product-url
需要将它们转换为:
example.com/user/john
example.com/product/product-url
如何根据页面定义单独的第二个键?
答案 0 :(得分:0)
您可以使用:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
RewriteRule ^user/([^/]+)/?$ index.php?page=user&id=$1 [NC,QSA,L]
RewriteRule ^product/([^/]+)/?$ index.php?page=product&url=$1 [NC,QSA,L]
RewriteRule ^([a-zA-Z0-9-]+)/?$ index.php?page=$1 [QSA,L]