我试图调整现有网站的结构,同时将URL重写为更方便用户的格式。我现在拥有的是一个 http://example.com/test_vars.php?test_var1=value1&test_var2=value2
,理想的情况是,我要的是 http://example.com/test_vars/test_var1/value1/t_var2/value2
。
诚然,我刚开始修改Htaccess文件,但做了一些研究并尝试了几件事情。 我最接近我所寻找的东西(当然不是那么近),但我附上了以下代码:
Options +FollowSymLinks
Options +Indexes
RewriteEngine on
DirectoryIndex index.html
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(([^/]+/)*[^.]+)$ /$1 [L]
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.html
RewriteRule .* index.html
有了这个,我最后有了一个 http://example.com/test_vars.php/test_var1/value1/test_var2/value2
的 URL,但是,没有一个变量被传送到页面上。