.htaccess将查询字符串附加到内部重定向 [英] .htaccess appending query string to internal redirect

查看:51
本文介绍了.htaccess将查询字符串附加到内部重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在.htaccess中创建SEO友好的蒙版重写. htaccess文件可以在localhost和我的个人服务器上正常工作,但不幸的是,它似乎在GoDaddy的服务器上无法正常工作.我知道那里已经是一个问题,但是要为打算使用Godaddy作为主机的客户工作.

I’m trying to create SEO friendly masked rewrites in .htaccess. The htaccess file works fine on localhost, and my personal server, but seems unfortunately does not work on GoDaddy’s servers. I'm aware that that's already an issue there, But working for a client who's set on using Godaddy as their host.

问题在于,重写似乎强制了重定向,而不是将其保留在内部,该重定向在浏览器URL栏中显示了重写的查询字符串. 例如.

The issue is that the rewrite seems to be forcing a redirect showing the rewritten querystring in the browser URL bar instead of keeping it internal. eg.

规则:

RewriteRule ^/?([a-zA-Z0-9-_/]*)$ /index.php?loadPage=$1&mode=cms [L,QSA]

链接:/images重定向到/images/?loadPage=images&mode=cms

对于浏览器,此应"保留为/images/.我在下面复制了我的简短.htaccess,为开发模块修改了IPs

this "should" stay as /images/ for the browser. I have copied my short .htaccess below, IPs modified for the development block

<Files .htaccess>
    deny from all
</Files>

Options -MultiViews +FollowSymlinks -Indexes

RewriteEngine On
RewriteBase /

# Stop Old redirection from block below
RewriteCond %{REQUEST_URI} "/old/"
RewriteRule (.*) $1 [L]

# Under construction Redirect
RewriteCond %{REMOTE_ADDR} !^0.0.0.0
RewriteCond %{REQUEST_URI} !^/?old/
RewriteRule ^/?(.*) "/old/$1″ [L,QSA]

#Admin utilities rewrite
RewriteRule ^/?admin/?(.*)$ /index.php?loadPage=$1&mode=backend [L,QSA]

#CMS/Frontend rewrites -- this one is failing
RewriteRule ^\/?([a-zA-Z0-9-_]+)\/?$ /index.php?loadPage=$1&mode=cms [QSA,L]

可能需要注意的一点是,显示的URL是/images/?query_string,而不是index.php?query_string,因此尽管外部请求从页面请求接收到301响应,但它没有进行完全重定向.

A hint of potential note is that the displayed url is /images/?query_string, NOT index.php?query_string, so it's not doing a full redirect, though external requests are receiving a 301 response from the page request.

推荐答案

我没有测试任何东西,只是看那条线...

I haven't tested anything but simply looking at that line...

RewriteRule ^\/?([a-zA-Z0-9-_]+)\/?$ /index.php?loadPage=$1&mode=cms [QSA,L]

存在语法错误. 9后面的连字符应从技术上作为范围指示符进行转义.大多数情况下,您会看到人们将其放在]的末尾,因此它不会引起错误,因此大多数人认为他们不必逃避它.您也不需要转义正斜杠.另外,使用问号会使上一个成为可选内容,并且不知道为什么要这么做.所以应该是这样的:

there is a syntax error. The hyphen after the 9 should be escaped as technically that is a range indicator. Most of the time you see people place it at the end before the ] and so it doesn't cause an error and so most people think they don't have to escape it. You also do not need to escape the forward slashes. Also using the question mark makes the previous optional, and don't know why you want that. So it should be like this:

RewriteRule ^([a-zA-Z0-9\-_]+)/?$ /index\.php?loadPage=$1&mode=cms [QSA,L]

这篇关于.htaccess将查询字符串附加到内部重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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