查询字符串破页字符串

2023-09-02 11:27:53 作者:┇魔帝殤邪┆

输入链路上的一个谷歌Analytics(分析)查询字符串打破我的网站的显示。

有谁知道为什么下面的会导致我的网站无法正常加载其主页(它似乎prevent一些插件的加载该页面需要)

  http://mysite.com/?utm_medium=email
 

虽然这并不:

  http://mysite.com/#utm_medium=email
 

如果你知道为什么,我该如何解决这一问题?我使用的查询字符串的方法传入的联系,他们都导致访问者看到一个破碎的主页。

该网站使用pretty的网址所以有需要的站点路由没有查询字符串。我试图简单地删除通过Apache重写查询字符串(这是很容易做到,工作,我在下面的例子),但是我认为谷歌Analytics(分析)将无法跟踪它需要什么,如果我这样做。

Python在网页中查找字符串

下面是在情况因素是我的的.htaccess

 #BEGIN字preSS
< IfModule mod_rewrite.c>
RewriteEngine叙述上
的RewriteBase /

#拉手重定向从https到http
的RewriteCond%{} HTTPS = ON
(。*)重写规则^ $的http://%{HTTP_HOST} / $ 1 [L,R = 301]

#什么将剥去URL查询字符串示例
#RewriteCond%{THE_REQUEST} ?[^ ] +
#RewriteRule(。*)/ $ 1〜 [R = 301,L]

重写规则^指数 .PHP $  -  [L]
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则。的index.php [L]
< / IfModule>
#结束字preSS
 

除了@ FAA的解决方案,并纳入@爱德华多的位到这一点,我还需要从受影响排除admin目录。我加入这样做:

 的RewriteCond%{REQUEST_URI}!^  / *(可湿性粉剂管理员)
 

解决方案

虽然这并不: http://mysite.com/#utm_medium=email

如果使用的作品,是一个有效的选择,而不是在查询中的问号,你可以尝试这样的:

 #什么的例子会剥夺来自URL查询字符串
的RewriteCond%{QUERY_STRING}。
重写规则^(。*)/ $ 1号%{QUERY_STRING}? [R = 301,L,NE,NC]
 

重定向

http://mysite.com/?query

http://mysite.com/#query

A Google Analytics query string on an incoming link breaks the display of my site.

Does anyone know why the following would cause my site to fail to load its homepage properly (it appears to prevent the loading of some plugins that the page needs)

http://mysite.com/?utm_medium=email

While this does not:

http://mysite.com/#utm_medium=email

And if you know why, how do I fix this? I have incoming links that use the query string method and they are all resulting in the visitor seeing a broken homepage.

The site uses "pretty urls" so there are no query strings needed for the site routing. I tried simply removing the query string via apache rewrite (which is easy to do and works, I give an example below) but then I assume Google Analytics won't be able to track what it needs if I do this.

Here is my .htaccess in case that factors into it:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# Handle redirection from https to http
RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301]

# Example of what would strip query strings from url
#RewriteCond %{THE_REQUEST} ?[^ ]+
#RewriteRule (.*) /$1? [R=301,L]

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

Extra

In addition to @faa's solution and incorporating @Eduardo's bit into this I also needed to exclude the admin directory from being affected. I did this by adding:

RewriteCond %{REQUEST_URI} !^/*(wp-admin)

解决方案

"While this does not: http://mysite.com/#utm_medium=email"

If using # works and is a valid option instead of the question mark in the queries, you may try something like this:

# Example of what would strip query strings from url
RewriteCond %{QUERY_STRING} .
RewriteRule ^(.*) /$1#%{QUERY_STRING}? [R=301,L,NE,NC]

Redirects

http://mysite.com/?query to

http://mysite.com/#query