[英]URL rewrite more than one php file
I got an problem with url rewriteing. 网址重写时出现问题。 First of all i am starting to think that i am making mistake in the structure of my webpage.
首先,我开始认为我在我的网页结构中犯了错误。 I made more than one php file.
我制作了多个php文件。 I think that this is mistake because in all tutorials and samples urls they are using in .htaccess only index.php.
我认为这是错误的,因为在所有教程和示例URL中,它们仅在.htaccess中使用index.php。
Info 1. I got in navigation tab index.php section1.php section2.php section3.php section4.php 2. In index.php i only have an basic information that won't change much. 信息1.我进入导航选项卡index.php section1.php section2.php section3.php section4.php 2.在index.php中,我只有基本信息,不会有太大变化。 3. In each section.php file i am echoing out list of articles.
3.在每个section.php文件中,我回显了文章列表。 4. each aricle got id and i am using it to echo out information when user clicks on article link.
4.每个文章都有ID,当用户单击文章链接时,我会用它来回显信息。 5. link to article " http://www.example.com/section1.php?id=607575 " 6. In each section.php file i got more than one page.
5.链接到文章“ http://www.example.com/section1.php?id=607575”。6 .在每个section.php文件中,我得到了多个页面。 7. For now my links to section page looks like this " http://www.example.com/section1.php?page=1 ".
7.现在,我到节页面的链接看起来像这样“ http://www.example.com/section1.php?page=1 ”。 Questions
问题
Qestions Qestions
<a href="http://www.example.com/section1.php?page=1>section1</a>
do i need to manually rewrite them OR it dose not matter, .htaccess will do the job? <a href="http://www.example.com/section1.php?page=1>section1</a>
,我是否需要手动重写它们,否则.htaccess没关系会做这份工作吗? if i need to rewrite url will it looks like this? 如果我需要重写url,它会像这样吗?
<a href="http://www.example.com/section1.php/section1/page/1">section1</a>
How to rewrite urls so they look like this www.example.com/section1/page/1 and www.example.com/section1/article/607575 (i know it's bad to use only numbers, i just need to understand how it works,then i will figure it out,how to replace it with article name). 如何重写网址,使其看起来像这样:www.example.com/section1/page/1和www.example.com/section1/article/607575(我知道仅使用数字是很不好的,我只需要了解其工作原理即可,那么我会弄清楚,如何用商品名称替换它)。
If I understand correctly, this is how you would rewrite: 如果我理解正确,这是您的重写方式:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ /path/to/section1.php?page=$ [QSA,L]
I'm not very used to mod_rewrite but that should work. 我不太习惯mod_rewrite,但是应该可以。 You might have to rewrite rule for ?article too.
您可能还必须重写文章的规则。
If this was not answered correctly, please refer to http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html 如果回答不正确,请参考http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
From: http://www.example.com/section1/page/1
来自:
http://www.example.com/section1/page/1
: http://www.example.com/section1/page/1
To: http://www.example.com/section1.php?page=1
前往:
http://www.example.com/section1.php?page=1
: http://www.example.com/section1.php?page=1
RewriteRule ^section(\\d+)/page/(\\d+)$ /path/to/section$1.php?page=$2
From: http://www.example.com/section1/article/607575
来自:
http://www.example.com/section1/article/607575
: http://www.example.com/section1/article/607575
To: http://www.example.com/section1.php?id=607575
收件人:
http://www.example.com/section1.php?id=607575
: http://www.example.com/section1.php?id=607575
RewriteRule ^section(\\d+)/article/(\\d+)$ /path/to/section$1.php?id=$2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.