【问题标题】:removing url query string删除 url 查询字符串
【发布时间】:2013-12-16 15:53:44
【问题描述】:

我有这个链接: http://joa.upcreation.com/nos-restaurants/cesar-palace/?plan=1

我想要这个: http://joa.upcreation.com/nos-restaurants/cesar-palace/plan

我试过了,但是不行……

 RewriteCond %{QUERY_STRING} ^(.*)$ 
 RewriteRule (.*) $1? [R=301,L] #remove query string

这里是我的 .htaccess

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} .+

RewriteRule ^(.*)$ /$1/plan? [NE,R=301,L]

RewriteBase /



AddType x-mapp-php5 .php

SetEnv PHP_VER 5



RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]

RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^ - [L]

RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]

RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]

RewriteRule . index.php [L]

谁能帮帮我?

提前致谢

【问题讨论】:

    标签: .htaccess url


    【解决方案1】:

    您可以将 incoming URI 设为/nos-restaurants/cesar-palace/plan,并使用 .htaccess 将其转换为服务器可以处理的形式:/nos-restaurants/cesar-palace/?plan=1。你不能走另一条路!您必须添加查询字符串。

    【讨论】:

      【解决方案2】:

      你可以使用这条规则:

      RewriteCond %{QUERY_STRING} .+
      RewriteRule ^(.*)$ /$1/plan? [NE,R=301,L]
      

      完整的.htaccess:

      #AddType x-mapp-php5 .php
      SetEnv PHP_VER 5
      Options +FollowSymLinks
      
      RewriteEngine On
      RewriteBase /
      
      RewriteCond %{QUERY_STRING} .+
      RewriteRule ^(.*?)/?$ /$1/plan? [NE,R=301,L]
      
      RewriteRule ^([\w-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
      
      RewriteCond %{REQUEST_FILENAME} -f [OR]
      RewriteCond %{REQUEST_FILENAME} -d
      RewriteRule ^ - [L]
      
      RewriteRule ^([\w-]+/)?(wp-(content|admin|includes).*) $2 [L]
      
      RewriteRule ^([\w-]+/)?(.*\.php)$ $2 [L]
      
      RewriteRule . index.php [L]
      

      更新::卷曲输出:

      curl -k -3 -L -I 'http://joa.upcreation.com/nos-restaurants/cesar-palace/?plan=1'
      HTTP/1.1 301 Moved Permanently
      Date: Wed, 18 Dec 2013 19:52:52 GMT
      Server: Apache
      Location: http://joa.upcreation.com/nos-restaurants/cesar-palace/plan
      Content-Type: text/html; charset=iso-8859-1
      
      HTTP/1.1 301 Moved Permanently
      Date: Wed, 18 Dec 2013 19:52:52 GMT
      Server: Apache
      X-Powered-By: PHP/5.2.17
      X-Pingback: http://joa.upcreation.com/xmlrpc.php
      Expires: Wed, 11 Jan 1984 05:00:00 GMT
      Cache-Control: no-cache, must-revalidate, max-age=0
      Pragma: no-cache
      Location: http://joa.upcreation.com/plan-du-site/
      Content-Type: text/html; charset=UTF-8
      
      HTTP/1.1 200 OK
      Date: Wed, 18 Dec 2013 19:52:53 GMT
      Server: Apache
      X-Powered-By: PHP/5.2.17
      X-Pingback: http://joa.upcreation.com/xmlrpc.php
      Link: <http://joa.upcreation.com/?p=99>; rel=shortlink
      Content-Type: text/html; charset=UTF-8
      

      【讨论】:

      • 谢谢!但这会将我重定向到另一个目录:joa.upcreation.com/plan-du-site
      • ok 试试看,这条规则实际上应该放在 DocumentRoot/.htaccess 中,而不是放在子目录中
      • 实际上它已经在 documentRoot 中,但在我的 .htaccess 中我还有其他规则:
      • 嗯,在这种情况下,请确保上述规则是您的 .htaccess 中的 第一条规则
      • 您也可以看到这里无法阅读代码。请将其发布在您的问题中
      猜你喜欢
      • 2011-02-02
      • 1970-01-01
      • 2016-07-22
      • 2011-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多