URL隐式重写-如何防止重写的URL出现在地址栏中? [英] URL Rewriting invisibly - How to prevent rewritten URL to appear in the address bar?

查看:242
本文介绍了URL隐式重写-如何防止重写的URL出现在地址栏中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我浏览了其他主题,其中包括:

I have browsed the other topics, including this one: Mod_rewrite invisibly: works when target is a file, not when it's a directory, but I can't find a solution to my problem.

我有以下重写规则:

RewriteRule ^([a-zA-Z0-9_-]+)$ ./index.php?s=$1 [L,NC]
RewriteRule ^([a-zA-Z0-9_-]+)/$ ./index.php?s=$1 [L,NC]

它的作用是将http://myaddress/parameter之类的内容写入http://myaddress/index.php?s=parameter,并在浏览器的地址栏中显示此新重写的地址.

What it does is to write anything like http://myaddress/parameter to http://myaddress/index.php?s=parameter and show this new rewritten address in the browser's address bar.

如何在地址栏中不显示重写的URL的情况下进行重写?

How can I make rewriting without showing the rewritten URL in the address bar?

修改

这是我的.htaccess文件的内容:

This is the content of my .htaccess file:

DirectoryIndex index.php

RewriteEngine On

RewriteRule ^([a-z0-9_\-]+)/?$ index.php?s=$1 [L,NC,QSA]
RewriteRule ^([a-zA-Z0-9_-]+)\/?([a-zA-Z0-9_-]+)\/?$ index.php?u=$1&s=$2 [L,NC]
RewriteRule ^([a-zA-Z0-9_-]+)\/?([a-zA-Z0-9_-]+)\/?([a-zA-Z0-9_-]+)\/?$ index.php?u1=$1&u2=$2&s=$3 [L,NC]

推荐答案

1.不需要两个执行相同工作的规则(唯一的区别是尾部有斜杠).

1. No need for 2 rules that do the same job (the only difference is presence of trailing slash).

2.如果您具有[NC]标志,则无需在模式中使用a-zA-Z-a-z就足够了.

2. No need to have a-zA-Z in pattern if you have [NC] flag -- a-z is enough.

3.尝试不带./

考虑到上述所有规则,该规则将变为:

Considering all the above mentioned the rule will become:

RewriteRule ^([a-z0-9_\-]+)/?$ index.php?s=$1 [L,NC,QSA]

PS 我还添加了QSA标志以保留原始查询字符串(如果存在).

P.S. I have also added the QSA flag to preserve original query string (if present).

该规则已经过测试,并且工作正常.如果仍然无法使用,请发布 ALL 重写规则.

The rule is tested and is working fine. If it still does not work for you then post ALL rewrite rules that you have.

这篇关于URL隐式重写-如何防止重写的URL出现在地址栏中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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