我想要以不同方式访问的网址:
原文:mywebsite.com/index.php?page=index
新:mywebsite.com/index
我这样做.htaccess:
RewriteEngine on
# The two lines below allow access to existing files on your server, bypassing
# the rewrite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?page=$1 [QSA]
下一个网址(从索引链接):
原文:mywebsite.com/index.php?page=hotel&hotel=5
新:mywebsite.com/hotel/5
我找到了一些有关多个参数的信息,但我无法让它们发挥作用。
答案 0 :(得分:3)
您可以为2个参数使用新规则:
RewriteEngine on
RewriteBase /
# The two lines below allow access to existing files on your server, bypassing
# the rewrite
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/?$ index.php?page=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?page=$1&hotel=$2 [L,QSA]