如何使用 .htaccess 隐藏在 url 中传递的参数 [英] How to hide params passed in url using .htaccess

查看:34
本文介绍了如何使用 .htaccess 隐藏在 url 中传递的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个特殊的情况,我的网站就像

I have a peculiar situation, my website is like

www.example.com/page.php?url=homepage

.我正在尝试使用 .htaccess 文件使 url 看起来像

. I am trying to use .htaccess file to make url look like

www.example.com/page/homepage/

通过隐藏网址中的.php?url="部分.这可能吗?请提出建议.

There by hiding the ".php?url=" part in the url. is this possible? please suggest.

推荐答案

试试这个:

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /

# /anything/anything -> anything.php?url=anything
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9_])/([^/]*)$ /$1.php?url=$2 [L]

</IfModule>

如果 page.php 文件名总是相同的,那么这样做:

If the page.php filename will always be the same, then do it like this:

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /

# /page/anything -> page.php?url=anything
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^page/([^/]*)$ /page.php?url=$1 [L]

</IfModule>

这篇关于如何使用 .htaccess 隐藏在 url 中传递的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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