.htaccess重写结构化模块的规则


.htaccess rewrite rule for structured modules

我使用的文件夹结构如下:当前URL:http://test.com/modules/login/login.php?v=1&v2=2&v3=3

我正在尝试:http://test.com/modules/login/login/v/1/v2/2/v3/3

我的根文件开始于:http://test.com/

我正试图编写.htaccess来从URL中隐藏GET方法值和.php文件名,但由于URL更为树形结构,我面临问题。

RewriteEngine On
RewriteRule ^([^/]+)/([^/]+)$  login.php?$1=$2 [QSA,L]
RewriteRule ^([^/]+)/([^/]+)$  login.php?$1=$2&$3=$4 [QSA,L]
RewriteRule ^([^/]+)/([^/]+)$  login.php?$1=$2&$3=$4&$5=$6 [QSA,L]

以上方法不起作用?

我们需要为单个文件编写规则吗?它可以在单个规则中完成吗??

我还尝试了以下内容:

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ login.php?user=$1&page=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ login.php?user=$1&page=$2

我的文件夹结构:

----Myproject
-------Config
------------config.php
-------Includes
------------Images
-----------------image.jpg
------------CSS
-----------------test.css
------------JS
-----------------test.js
-------Modules
------------Home
-----------------index.php
------------settings
-----------------config.php
------------login
-----------------login.php
------------Contact 
------------MyPage
-------(.htaccess)

DOCUMENT_ROOT/.htaccess文件中使用以下代码:

RewriteEngine On
RewriteRule ^(modules/[^/]+/[^/]+)/([^/]+)/([^/]+)(/.*)?$ /$1/$4?$2=$3 [L,QSA,NC]
RewriteCond %{REQUEST_URI} !'.php$
RewriteRule ^(modules/[^/]+/[^/]+)/?$ /$1.php [L,NC]

外部重定向:

RewriteRule ^(modules/[^/]+/[^/]+)/([^/]+)/([^/]+)(/.*)?$ /$1/$4?$2=$3 [L,QSA,NC]
RewriteCond %{REQUEST_URI} !'.php$
RewriteRule ^(modules/[^/]+/[^/]+)/?$ /$1.php [L,NC,R]

使用以下代码

RewriteEngine On
RewriteBase /give your full path of your project/
#for hidding get request
# Redirect /login?id=2 to /login/2
RewriteCond %{THE_REQUEST}^[A-Z]/+login'?id=([^&'s]+) [NC]
RewriteRule ^ /login?%1 [R=302,L]
#for hidding .php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}'.php -f
RewriteRule ^(.*)$ $1.php [QSA,L]

你想做什么?传入的URL(搜索引擎友好型/SEO?)是什么样子的,需要将其转换为什么才能使PHP文件使用它?您的问题说明非常模糊。举几个例子。