.htaccess RewriteRule查询字符串的路径

时间:2018-07-25 15:37:01

标签: .htaccess mod-rewrite

我正在尝试实现一个类似的网址

example.com/ 路径1 到example.com/index.php?p1= 路径1

example.com/ path1 / path2 到example.com/index.php?p1= path1 &p2 = path2 < / strong>

在我的.htaccess中,我有:

RewriteEngine On

RewriteRule ^(.*)/(.*)$ /index.php?c=$1&g=$2 [NC,L]

RewriteRule ^([a-zA-Z0-9-_]+)$ /index.php?g=$1 [NC,L]

对于拥有example.com/path1 / path2 的情况,效果很好,但对于example.com/ path1 的情况,效果很好>仅在网址中没有点时有效。例如,我希望example.com/mydomain.com可以工作到example.com/index.php?g=domain.com,但我无法使其正常工作。

您能帮我吗?

1 个答案:

答案 0 :(得分:0)

这是我的处理方式:

@implementation SecondViewController
   NSArray *urlArray;
   NSArray *nameArray;
   NSArray *authorArray;


   - (void)viewDidLoad {
       [super viewDidLoad];

       urlArray = [AppConstant url];
       nameArray = [AppConstant name];
       authorArray = [AppConstant author];


   }

@end

然后,无论您使用哪种服务器端语言,我都会使用PHP解析$ _GET ['param']。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?params=$1