htaccess如何从URL删除/ home

时间:2018-08-11 11:58:45

标签: .htaccess

文件夹:

  • ROOT
      • home.php
      • contact.php
    • .htaccess

htaccess:

# Load files from pages folder 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+pages/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^pages/)^(.*)$ /pages/$1 [L,NC]

# Default index.php
DirectoryIndex home.php
RewriteRule ^/?$ /home [L,R]

这可行,但是当我打开 localhost:1993 时,它将地址更改为 localhost:1993 / home 。我应该如何编辑htaccess以便不出现 / home ? (仅适用于 localhost:1993 )。

我的请求是:

  • localhost:1993 重定向到 localhost:1993 (隐藏 / home
  • localhost:1993 / contact 重定向到 localhost:1993 / contact

1 个答案:

答案 0 :(得分:0)

RewriteRule ^contact$ pages/contact.php [NC,L,QSA]

RewriteRule ^([a-zA-Z0-9-]*)$ pages/$1.php [NC,L,QSA]

查询版本:

RewriteRule ^([a-zA-Z0-9-]*)/(.*)$ pages/$1.php?query=$2 [NC,L,QSA]