.htaccess rewriteRule(./index.php?page=projects&id=$1) [英] .htaccess rewriteRule (./index.php?page=projects&id=$1)

查看:129
本文介绍了.htaccess rewriteRule(./index.php?page=projects&id=$1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用htaccess重写URL,但是我有一些问题希望能对我有所帮助。

I'm trying to rewrite the URL using htaccess, but I have some problems that I hope you could help me with.

这是我的内容。 htaccess文件

This is the contents of my .htaccess file

RewriteEngine On  

RewriteCond %{SCRIPT_FILENAME} !-d  
RewriteCond %{SCRIPT_FILENAME} !-f  

RewriteRule ^(.*)$ ./index.php?page=projects&id=$1

以下规则非常有效,它可以转换以下网址:

The following rule works great, it converts this url:

peterboruplund.dk/?page=projects&id=projectname

为此

peterboruplund.dk/projectname

问题是我还希望只能查看一个页面。就像我写这个网址一样:

But the problem is that I also want to be able to only view a page. Like if I write this url:

peterboruplund.dk/?page=info

它应该转到名为信息的页面,如下所示:

It should go to the page called "info", like this:

peterboruplund.dk/info

我的问题是我如何才能同时达到这两个目标

My problem is how can I achieve both things at the same time?

最好,彼得

推荐答案

/ info 的另一条规则:

RewriteEngine On  

RewriteCond %{SCRIPT_FILENAME} !-d  
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([^/]+)/?$ ?page=$1 [L,QSA,NC]

RewriteCond %{SCRIPT_FILENAME} !-d  
RewriteCond %{SCRIPT_FILENAME} !-f  
RewriteRule ^(.+)$ index.php?page=projects&id=$1 [L,QSA]

这篇关于.htaccess rewriteRule(./index.php?page=projects&id=$1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆