正如标题所说,我是“URL重写”领域的新手,我想问一个问题,可以帮助许多像我一样的人。
假设我们有一个这样的url:
http://myepicsite.wow/index.php?value_x=1&value_y=2&value_z=3如何才能在不为那些_GET[]变量生成的每个页面编写一行代码的情况下,将这个url重写为类似这样的内容?
http://myepicsite.wow/index.php/1/2/3发布于 2015-09-28 08:46:30
尝试:
RewriteEngine On
RewriteRule ^index\.php/([^/]+)/([^/]+)/([^/]+)$ /index.php?value_x=$1&value_y=$2&value_z=$3 [L,QSA]然后你只需要确保你的链接看起来都像http://myepicsite.wow/index.php/1/2/3。
但是,即使没有重写规则,您也可以从index.php中读取这些内容。在您的index.php脚本中,您应该能够读取$_SERVER['PATH_INFO']变量并看到值,然后将其分解成一个数组,并将它们赋给/1/2/3 _x/y/z变量。
发布于 2015-09-28 08:43:43
尝试将其添加到您的.htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^myepicsite.wow [NC]
RewriteRule ^(.*)$ http://myepicsite.wow/$1 [L,R=301]
RewriteRule ^index.php/(.+)/(.+)/(.+)/?$ index.php?value_x=$1&value_y=$2&value_z=$3&%{QUERY_STRING} [L]https://stackoverflow.com/questions/32814267
复制相似问题