url重写htaccess问题

时间:2017-04-21 13:28:02

标签: php .htaccess

我有网址:

  

http://127.0.0.1/myfolder/index.php

     

http://127.0.0.1/myfolder/index.php?error=1 ...

我该如何制作

  

http://127.0.0.1/rewritedpath/(index.php)

     

http://127.0.0.1/rewritedpath/error/1(index.php?error = 1)

我已经死了

RewriteEngine on
RewriteRule ^/?rewritedpath/ /myfolder/index.php
RewriteRule ^/?rewritedpath/error/([0-9]+)$ /myfolder/index.php?error=$1

但这不起作用。这有什么不对?感谢

已更新

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?rewritedpath/error/([0-9]+)$ /myfolder/index.php?error=$1 [L]
RewriteRule ^/?rewritedpath/ /myfolder/index.php [L]

2 个答案:

答案 0 :(得分:1)

尝试使用以下规则,

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?rewritedpath/ /myfolder/index.php [L]
RewriteRule ^/?rewritedpath/error/([0-9]+)$ /myfolder/index.php?error=$1 [L]

答案 1 :(得分:1)

假设你的myfolder位于

/无功/网络/ HTML / MyFolder文件

  1. 确保myfolder中的index.php
  2. 在/ var / www / html / rewritedpath /
  3. 中创建.htaccess
  4. 将此代码写入新创建的.htaccess文件
  5. RewriteEngine On

    RewriteRule ^(.*)$ ../myfolder/index.php?params=$1 [NC]

    1. 将此登录信息写入位于myfolder
    2. index.php文件中

      $get = explode("/",$_GET['params']);

      <$>在$ get at $ get [0]你将获得你的关键错误,$ get [1]你将获得你的价值。

      它将解析数组中的所有url参数。