【问题标题】:RedirectMatch: Remove question markRedirectMatch:删除问号
【发布时间】:2012-11-16 11:17:12
【问题描述】:

我正在使用RedirectMatch 将旧网站重定向到新网址。 (我不需要保留原始查询字符串,因此末尾有“?”)。

RedirectMatch 301 ^/cms/index.php$ http://www.mysite.com?

重定向有效,但是重定向后我在结束 URL 处留下了一个难看的问号:

www.mysite.com?

有什么办法可以去掉吗?

编辑:我正在输入我目前正在使用的 .htacces 文件:

RedirectMatch 301 ^/cms/index.php$ http://www.mysite.com?

# BEGIN WPSuperCache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
AddDefaultCharset UTF-8
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$
RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC]
RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f
RewriteRule ^(.*) "/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz" [L]

RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$
RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC]
RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f
RewriteRule ^(.*) "/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html" [L]
</IfModule>

# END WPSuperCache

RewriteCond %{HTTP_HOST} ^mysite.com$
RewriteRule ^(.*)$ "http\:\/\/www\.mysite\.com\/$1" [R=301,L]




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

# END WordPress

编辑:最后我使用 anubhava 建议让它工作了。但是我必须在/cms 文件夹中创建一个单独的.htaccess 文件。

【问题讨论】:

    标签: .htaccess redirect


    【解决方案1】:

    最好使用这样的代码来使用 mod_rewrite:

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^cms/index\.php$ http://www.mysite.com/? [L,R=301,NC]
    

    【讨论】:

    • 感谢您的快速回答!我尝试粘贴您的代码,但它不会将我重定向到任何地方。 (是的,它在我的 .htaccess 的第 1 行)。出于某种原因,似乎只有redirectmatch 对我有用...
    • 确保通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放入DOCUMENT_ROOT目录下的.htaccess
    • mod_rewrite 已明确启用,因为我在同一个域上使用 wordpress - 我的 .htaccess 文件中还有其他几个(与 wordpress 相关的)重写规则。我正在发布我的 .htacces,以便您查看...
    • 清除浏览器缓存,然后重新启动浏览器并在RewriteBase / 行下方插入我建议的 RewriteRule。
    • 我完全按照你的建议做了,仍然没有运气。唯一可行的是我在第 1 行的方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 2014-02-15
    • 2014-09-12
    • 2014-09-08
    相关资源
    最近更新 更多