繁体   English   中英

从查询到子目录HTACCESS中的路径

[英]from query to path in subdirectory HTACCESS

我在根目录中安装了一个带有WordPress的https域。 在子目录“ / test /”中,我创建了一个使用GET进行工作的Web应用程序; 路径是这样的:

https://www.example.com/test/file.php?url=urlname&etc=etc

我需要将其转换为:

https://www.example.com/test/urlname/?etc=etc

我还需要从第一种网址重定向到第二种网址。

这是我第一次必须编辑htaccess文件,并且在网上搜索后尝试了此代码

RewriteRule ^/?test/([^/]+)/$ test/file.php?url=$1&%{QUERY_STRING} [L,QSA]
RewriteCond %{REQUEST_URI}  ^/test/file\.php$
RewriteCond %{QUERY_STRING} ^url=(.*)$
RewriteRule ^/?test/file\.php$ /test/%1/?%{QUERY_STRING}  [L,R=301]

但显然不起作用。 有人能帮我吗?

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

RewriteEngine On
RewriteBase /

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /test/file\.php\?url=([^\s&]+)(?:&(\S*))?\s [NC]
RewriteRule ^ /test/%1?%2 [R=301,L,NE]

# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^test/([^/]+)/?$ test/file.php?url=$1 [L,QSA,NC]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM