【问题标题】:.htaccess Rewrite Rules redirection.htaccess 重写规则重定向
【发布时间】:2020-11-01 06:11:06
【问题描述】:

我正在尝试将我的 .htaccess 配置为指向任何如下所示的 URL:

DOMAIN/something

到这个网址:

DOMAIN/index.php?title=something

还没有在浏览器中保留原始 URL。

我试过这样做:

RewriteEngine On  
RewriteRule ^/(. *)$  /index.php?title=$1

但是没用

【问题讨论】:

  • 我不确定这是否只是 SO 上的一个错字,或者您的 .* 之间是否真的有空格,但该正则表达式不会满足您的要求。试试看:RewriteRule ^(.*)$ /index.php?title=$1

标签: apache .htaccess web redirect


【解决方案1】:

尝试使用 [R] 在重定向规则中添加 RewriteRule 标志。 使用 [R] 标志会导致向浏览器发出 HTTP 重定向。可以使用 [R=305] 之类的语法指定任何有效的 HTTP 响应状态代码,如果未指定,则默认使用 302 状态代码。 [R=301] 用于将用户重定向到新位置。

不是这个

RewriteEngine On  
RewriteRule ^/(. *)$  /index.php?title=$1

试试这个:

RewriteEngine On  
RewriteRule ^/(. *)$  /index.php?title=$1 [R=301]

【讨论】:

  • 这与 OP 的要求相反。他们说keep the original URL in the browserR 发出外部重定向,浏览器 URL 将更改。
猜你喜欢
  • 2016-06-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-22
  • 2013-01-21
  • 1970-01-01
相关资源
最近更新 更多