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

编程入门 行业动态 更新时间:2024-10-24 00:29:58
本文介绍了.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)

本文发布于:2023-11-01 23:16:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550693.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:index   php   htaccess   rewriteRule   amp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!