【问题标题】:htaccess to remove query string from a single urlhtaccess 从单个 url 中删除查询字符串
【发布时间】:2014-05-17 23:38:28
【问题描述】:

我已经研究了很多并看到了许多类似的帖子,但似乎没有解决方案适用于这种确切的情况。我想从我网站中的单个 URL 中删除查询字符串(但在其他地方保持所有其他查询字符串不变)。我正在使用生成 URL 的 wordpress:

http://mysite.net/wp-login.php?redirect_to=http%3A%2F%2Fmysite.net

不幸的是,我无法更改生成的 url,所以我想使用 HTACCESS 到 301 这只是:

http://mysite.net/wp-login.php

我当前的 HTACCESS 如下:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

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

# END WordPress
AuthType Basic
require valid-user

到目前为止,我已经尝试了许多建议的解决方案但没有成功,我怀疑这是因为与我当前的 htaccess 修改发生冲突导致 500 服务器错误。

任何帮助将不胜感激。

提前致谢。

【问题讨论】:

    标签: wordpress .htaccess query-string


    【解决方案1】:

    尝试在RewriteBase /下方添加此内容:

    RewriteCond %{QUERY_STRING} ^redirect_to=http%3A%2F%2Fmysite.net$
    RewriteRule ^wp-login\.php$ /wp-login.php? [L,R=301]
    

    【讨论】:

    • 工作就像一个魅力!谢谢乔恩林!
    • @user1527123 也接受答案 .. 让其他人知道这是正确答案,乔恩会得到分数 :)
    猜你喜欢
    • 1970-01-01
    • 2021-08-18
    • 1970-01-01
    • 2017-06-01
    • 1970-01-01
    • 2016-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多