目前我的网址结构如下:
http://mysite/index.php?page=main
http://mysite/index.php?page=bowling
http://mysite/index.php?page=inn
如何通过仅留下(主要,保龄球,旅馆)来优化这种结构?
答案 0 :(得分:0)
尝试将这些规则添加到文档根目录中的htaccess文件中:
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+index\.php\?page=([^&]+)&id=([0-9]+)
RewriteRule ^ /%1/%2? [L,R]
RewriteCond %{THE_REQUEST} \ /+index\.php\?page=([^&\ ]+)
RewriteRule ^ /%1? [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([0-9]+)/?$ /index.php?page=$1&id=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /index.php?page=$1 [L]
确保mod_rewrite已开启。