douzhangcuo2174
2014-08-19 08:49
浏览 80
已采纳

URL重写解析为地址栏中的实际URL

I have a strange issue where on some users machines the rewritten url's are resolving to their actual url in the address bar.

I have the following in my htaccess file

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

I have noticed these appearing in my analytics which is messing up my stats as there are two url's for one page.

An example of this is:

http://example.com/news/the-first-post

http://example.com/index.php?url=news/the-first-post

I have on occasion been able to replicate the issue myself by directly typing the rewritten URL in the address bar.

图片转代码服务由CSDN问答提供 功能建议

我有一个奇怪的问题,在某些用户机器上,重写的URL正在解析为地址栏中的实际URL。

我的htaccess文件中有以下内容

  RewriteEngine On 
RewriteCond%{REQUEST_FILENAME}!-d 
RewriteCond%{REQUEST_FILENAME}  !-f 
RewriteCond%{REQUEST_FILENAME}!-l 
RewriteRule ^(。+)$ index.php?url = $ 1 [QSA,L] 
   
 
 

I 我注意到这些出现在我的分析中,这弄乱了我的统计数据,因为一页有两个url。

这方面的一个例子是:

http://example.com/news/the-first-post

http://example.com/index。 php?url = news / the-first-post

我有时可以通过直接在地址栏中输入重写的URL来复制问题。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douduoting8408 2014-08-19 09:08
    已采纳

    Have your rules like this:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} \s/+index\.php\?url=([^\s&]+) [NC]
    RewriteRule ^ /%1? [R=301,L,NE]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
    

    Now all URLs with /index.php?url=news/the-first-post structure will be 301 (permanent) redirected to /news/the-first-post.

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题