[英]How can I rewrite a url by keeping the file name as it is but the parameter being passed should be the folder name?
我正在传递一个将用作子文件夹的名称,但文件名保持不变,例如 foldername/gallery.php?q=new_folder 应该是 new_folder/gallery.php 使用 htaccess。
附上我想做的事情的 htaccess
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(gallery.php)$ $2.php?q=$1 [L]
gallery.php
是文件名, $1
基本上是new_folder
。 已经为此苦苦挣扎了一段时间。
你相当接近。 您只需要在规则的目标 URI 中使用foldername/
。
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/(gallery\.php)$ foldername/$2.php?q=$1 [L,QSA,NC]
我刚刚在 .htaccess 中添加了下面提到的代码。 希望这会帮助你。
RewriteEngine On
RewriteRule ^foldername/(.*) http://example.com/newfolder/gallery.php?options=$1 [R=301,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.