【问题标题】:htaccess rewrite query string for all pageshtaccess 重写所有页面的查询字符串
【发布时间】:2015-05-18 15:14:45
【问题描述】:

我有这个以及它的作用,它会改变查询字符串,如下例所示:

<IfModule mod_rewrite.c>
#Options Allow All
DirectoryIndex index.php
RewriteEngine On
RewriteBase /folder/

RewriteRule ^page/([^/.]+)/?$ otherpage.php?id=$1 [L]

</IfModule>

所以如果我有这样的链接:

http://example.com/folder/otherpage.php?id=123

此 htaccess 将允许从以下位置访问该链接:

http://example.com/page/123

我想要更改查询字符串以查找我的任何(所有)页面(没有任何文件夹),例如:

http://example.com/mypage1.php?id=123

应该可以通过以下方式访问:

http://example.com/mypage1/page/123

和mypage2.php、page3.php等一样

【问题讨论】:

  • 是的,你可以删除它,它不会,但我不是那个。请看下面的答案和它的cmets
  • 不需要那个。找到了另一个删除 .php 的解决方案,它与下面的答案一起工作得很好

标签: .htaccess mod-rewrite


【解决方案1】:

尝试添加此规则:

RewriteRule ^([^/.]+)/page/([0-9]+)$ /$1.php?id=$2 [L]

【讨论】:

  • 它几乎可以工作,但它给出“500 Internal Server Error”,因为我也使用这个。没有这个,你的代码就可以完美运行:RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php 这使得页面可以在没有 .php 的情况下访问,我需要它。我应该怎么做才能让它们一起工作?
猜你喜欢
  • 2014-01-06
  • 2010-11-16
  • 1970-01-01
  • 1970-01-01
  • 2013-12-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多