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

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.

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?