【问题标题】:Hide index and rewriting URL parameters using htacess使用 htaccess 隐藏索引和重写 URL 参数
【发布时间】:2015-08-14 08:23:06
【问题描述】:

如何隐藏 index.php 并重写 URL 参数

http:example.com/www/index.php?page=admin&action=login

作为

http:example.com/www/admin/login

我使用下面提到的代码 (Helped from URL) 隐藏 index.php,它使 URL 为:

http:example.com/www/?page=admin&action=login

我的 htaccess 文件代码

  Options +FollowSymLinks -MultiViews
  # Turn mod_rewrite on
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?$1 [L,QSA]

  RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
  RewriteRule ^ %1 [R=301,L]

但我需要这样:

http:example.com/www/admin/login

如果有人知道,那将是一个很大的帮助。谢谢

【问题讨论】:

  • RewriteRule ^(.*)$ index.php?$1 [L,QSA] 更改为RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA] 现在您将能够像$_GET['rt'] = www/admin/login/ 一样在$_GET['rt'] 中获取请求uri,然后用/ 将其分解并使用它

标签: php apache .htaccess mod-rewrite url-rewriting


【解决方案1】:

您可以在/www/.htaccess中使用这些规则:

DirectoryIndex index.php
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /www/

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/([^/]+)/?$ index.php?page=$1&action=$2 [L,QSA]

RewriteRule ^(.+)$ index.php?$1 [L,QSA]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-09
    • 2013-08-13
    • 2012-06-23
    • 1970-01-01
    • 2018-12-08
    • 2015-07-21
    • 1970-01-01
    • 2016-10-03
    相关资源
    最近更新 更多