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 关于#.net#的问题:End Function
  • ¥50 用AT89C52单片机设计一个温度测量与控制电路
  • ¥15 无法import pycausal
  • ¥15 VS2022创建MVC framework提示:预安装的程序包具有对缺少的注册表值的引用
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义
  • ¥15 嵌入式--定时器使用
  • ¥20 51单片机学习中的问题
  • ¥30 Windows Server 2016利用兩張網卡處理兩個不同網絡
  • ¥15 Python中knn问题