如何在 URL 中添加多个名称? [英] How to add multiple name in the URL?

查看:65
本文介绍了如何在 URL 中添加多个名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有了解更多按钮,当使用时点击了解更多按钮,然后我必须重定向到product.php页.下面是我正在使用的代码,它正在运行.

I have know more button on my website and when the use click on know more button then I have to redirect to product.php page. Below is the code which i am using and it's working.

<a href="product">Know More</a>

现在我必须将 URL 从 http://example.com/product.php 重写为

Now I have to rewrite the URL from http://example.com/product.php to

http://example.com/products/products2/products3/products

我试过下面的代码

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

RewriteRule ^products/products2/products3/products$ product.php [L]

但它不起作用.你能帮我改写规则吗?

but it's not working. Would you help me out with rewrite rules?

我也试过了

RewriteRule ^products/products2/products3/products product.php

推荐答案

就这样:

RewriteEngine On

# match specific URI
RewriteRule ^products/products2/products3/products/?$ product.php [L,NC]

# php estension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

在 URI 前添加 .php 之前,请注意更改规则的顺序并检查是否存在 .php 文件.

Note changed order of your rules and checking for presence of .php file before adding .php in front of a URI.

这篇关于如何在 URL 中添加多个名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆