简体   繁体   English

使用get变量重写HTACCESS

[英]HTACCESS rewrite with get variables

I have a sub directory which has a bunch of .php files in it. 我有一个子目录,其中有一堆.php文件。 I currently have this as my .HTACCESS to rewrite the urls cleanly. 我目前将其作为.HTACCESS来干净地重写网址。

RewriteEngine on
Options +FollowSymLinks
RewriteBase /mailing_list

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

This is fine because it turns http://www.example.com/mailing_list/home to look at http://www.example.com/mailing_list/home.php 这很好,因为它使http://www.example.com/mailing_list/home查看http://www.example.com/mailing_list/home.php

What I also need to account for is a page using clean urls for the get variables. 我还需要说明的是一个使用干净的URL作为get变量的页面。 That page is called w.php and it passes ?i=(int) 该页面称为w.php,它通过?i=(int)

When I try to access http://www.example.com/mailing_list/w/1 I get a 505 server error. 当我尝试访问http://www.example.com/mailing_list/w/1时,出现505服务器错误。 What do I need to add to my htaccess to account for this? 我需要添加到我的htaccess中以解决此问题吗? Is there a full proof way which will account for others I run in to. 有没有一种完整的证明方法可以解释我所遇到的其他问题。 For example: 例如:

What if a page comes up called blogs and it passes the ID of the blog like this: http://www.example.com/mailing_list/blog/1 如果出现一个名为Blogs的页面,并且该页面传递了Blog的ID,例如: http : //www.example.com/mailing_list/blog/1 ,该怎么办

Will I have to add a new Rule for that page specifically? 我是否需要专门为该页面添加新规则?

Replace 更换

RewriteRule ^(.*)$ $1.php

by 通过

RewriteRule ^([^/]+)$ $1.php [L,QSA]
RewriteRule ^([^/]+)/(.*)$ $1.php?i=$2 [L,QSA]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM