【问题标题】:URL rewriting QUERY_STRING?URL 重写 QUERY_STRING?
【发布时间】:2014-08-13 09:50:03
【问题描述】:

我已经尝试并查找了很多您的帖子, 还不能让它工作。

来自网站的所有 URL 我有一个简单的 PHP 配置,像这个例子:

http://www.example.com/index.php?page=pagename

我想知道是否可以像这样隐藏 Quesry_String:

http://www.example.com/pagename/

在服务器配置中(apache 2.2 使用没有 .htaccess 的虚拟主机):

    DocumentRoot "/home/account/www/www.mysite.com/"
    Options -MultiViews
    DirectoryIndex index.php
    RewriteEngine On

    ## Rewrite 301 old Quesry_string (?p => ?page) ##
    RewriteCond %{QUERY_STRING} ^p=([^&]+) [NC]
    RewriteRule ^/$ /?page=%1 [R=301,L]

    ## Trying to hide query_string (not working) ##
    #RewriteCond %{QUERY_STRING} ^page=([^&]+) [NC]
    #RewriteRule ^/$ /%1 [R=301,L]
    #result => http://www.www.mysite.com/pagename?page=pagename (404)

    ## Rewrite 301 old page names ##
    RewriteCond %{QUERY_STRING} ^page=oldpagename$ [NC]
    RewriteRule ^/index\.php$ /?page=pagename/ [R=301,L]

    ## Remove index.php from url ##
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?)
    RewriteRule ^ /%1 [R=301,L]

    #Rewrite 301 index.html to root /
    RewriteRule ^/index.htm?$ index.html [NC,R=301,L]
    RewriteRule ^/index.html?$ / [NC,R=301,L]

我想我快到了,谢谢你的帮助。

【问题讨论】:

标签: rewrite query-string


【解决方案1】:

我猜它应该对你有用

重写规则 ^([^/.]+)/$ index.php?page=$1 [L]

【讨论】:

  • 我在评论时添加了它:## Remove index.php from url ## #RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\ .php($|\ |\?) #RewriteRule ^ /%1 [R=301,L] 它不会重写我会尝试不使用其他规则
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-27
  • 1970-01-01
  • 2020-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多