【发布时间】:2015-12-31 11:03:24
【问题描述】:
试图自己解决,但没有运气。
我有一个网站(PHP、Apache),其结构如下:
1. http://hostname/
2. http://hostname/category?list=listname
3. http://hostname/product?id=...&name=productname
4. http://hostname/recipes
5. http://hostname/recipe?id=...&name=recipename
+ many others.
当前 .htaccess 是:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
因此,例如 http://hostname/category?list=... 变为 /category.php?list... 然后它会捕获 php 脚本并运行。
我想制作这样的友好网址:
1. http://hostname/
2. http://hostname/category/listname/
3. http://hostname/product/productname/
4. http://hostname/recipes/
5. http://hostname/recipe/recipename/
另一方面,以前的网址必须仍然有效,因为网站已被搜索引擎大量索引。因此,从旧式网址它必须 301 重定向到新网址。 有任何想法吗? 我所有的努力都有错误。我什至尝试通过 index.php 入口点进行 PHP 路由,但我不知道如何处理旧式链接。
【问题讨论】:
标签: apache .htaccess mod-rewrite url-redirection friendly-url