[英]url rewrite path using htaccess and php
I'd like to rewrite the following path https://example.org/app/my/index.php?param=/foo/bar/
to https://example.org/app/my/foo/bar
and retrieve $_GET['param']
in php using .htaccess
.我想将以下路径https://example.org/app/my/index.php?param=/foo/bar/
重写为https://example.org/app/my/foo/bar
:// $_GET['param']
在 php 中使用.htaccess
。
The parameter has to be modular so it can be any path.该参数必须是模块化的,因此它可以是任何路径。 And I would like to keep the ability to add other parameter like https://example.org/app/my/foo/bar/?id=XY
而且我想保留添加其他参数的能力,例如https://example.org/app/my/foo/bar/?id=XY
The .htaccess
-file is in /app/my/
. .htaccess
文件位于/app/my/
中。
I already tried this, but it didn't worked out我已经尝试过了,但没有成功
RewriteEngine On
RewriteRule ^(app/my/[\w-]+)/([\w-]+)/?$ $1.php?param=$2 [L,NC,QSA]
You may use:您可以使用:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(app/my)/(.+)$ $1/index.php?param=$2 [L,NC,QSA]
Using RewriteCond %{REQUEST_FILENAME} !-f
to avoid matching app/my/index.php
or any other file inside that folder.使用RewriteCond %{REQUEST_FILENAME} !-f
来避免匹配app/my/index.php
或该文件夹中的任何其他文件。
You may try this rule inside app/my/.htaccess
:您可以在app/my/.htaccess
中尝试此规则:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.+$ index.php?param=$0 [L,QSA]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.