我想将“ rentful url”用于正在开发的网站。

http://mysite.com/Products/category=bags&colours=black

谁能告诉我如何使用.htaccess实现这一目标?

奥斯卡

有帮助吗?

解决方案

这是一个.htaccess,除了文件或目录冲突及其路由到 /index.php时,要捕获任何内容:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

因此,我们可以将 /index.php用作我们的请求路由器。在PHP中,我们只会得到类似的请求:

<?php
$url_path = $_SERVER['REQUEST_URI'];
// Parse your URL path here...

也就是说,您的URL模式是非标准的,我真的建议您反对它,因为代理和浏览器会编码ampersand and均等符号。让我提出以下内容之一(还可以使用小写,因为它有助于验证URL):

http://example.com/products/categories/bags/colours/black
http://example.com/products/category_bags/colours_black
http://example.com/products?category=bags&colours=black
http://example.com/products/categories/bags?colours=black
http://example.com/products/bags?colours=black

要查看URL路径中的内容,只需Google谷歌搜索Google的搜索URL即可。

希望这可以帮助。

-麦克风

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top