简体   繁体   English

如何在我的apache服务器中添加和使用mime类型

[英]How to add and use mime type to my apache server

I want to change my web url from www.site.com/maintenance.php?m=1 to a mime type url(as I was told) like www.site.com/maintenance/1. 我想将我的网址从www.site.com/maintenance.php?m=1更改为哑剧类型的url(如我所知),如www.site.com/maintenance/1。 How do I do that on a apache localhost server? 如何在apache本地服务器上执行此操作?

I heard you must do something with htaccess so I want to say 2 thing about my htaccess 我听说您必须对htaccess做一些事情,所以我想对我的htaccess做两件事

  1. My htaccess in located in htdocs/folder/ .htaccess because I have multiple sites in my htdocs so I out every site files in a folder 我的htaccess位于htdocs / folder / .htaccess中,因为我的htdocs中有多个站点,所以我将每个站点文件都放在一个文件夹中

  2. I already have this code in my htaccess. 我的htaccess中已经有此代码。 If you're going to ask whether it's working , yes it's working I stole it from some cpanel hosting for my custom 404 error page 如果您要询问它是否正常工作,是的,它在正常工作,我从某个cpanel托管那里偷了我的自定义404错误页面

http://i.stack.imgur.com/TpeZC.jpg http://i.stack.imgur.com/TpeZC.jpg

And also, how do I get the value of /1 after the /maintenance/? 而且,如何在/ maintenance /之后获取/ 1的值?

Thank you in advance 先感谢您

Use this in your .htaccess file 在您的.htaccess文件中使用它

RewriteEngine On
RewriteRule ^maintenance/(.*)$ maintenance.php?m=$1 [QSA,L]

You get the value of m as you normally get. 您会像平常一样获得m的值。 $m = $_GET['m'];

What you are trying to accomplish is called mod_rewrite , not changing mime type . 您要完成的任务称为mod_rewrite ,而不更改mime类型

In your case, you can try this inside your .htaccess file: 您可以在.htaccess文件中尝试以下操作:

RewriteRule ^maintenance/([0-9]+)$ maintenance.php?m=$1 [QSA,L]

Basically what the above means is that for every numerical values that follow "maintenance/" in your typed URL, take the number and pass it as the m value for "maintenance.php" script. 基本上,上面的意思是,对于键入的URL中跟在“ maintenance /”之后的每个数字值,请取数字并将其作为“ maintenance.php”脚本的m值传递。 So, in your "maintenance.php" file, you can access the value with $_GET['m'] . 因此,在您的“ maintenance.php”文件中,您可以使用$_GET['m']访问该值。

Note that if your m can accept anything other than numbers, or if your other files under "maintenance" folder can contain numbers only, thing gets a bit more complicated. 请注意,如果您的m可以接受数字以外的任何内容,或者如果“ maintenance”文件夹下的其他文件只能包含数字,则情况会变得更加复杂。 You will then need additional rules to filter out the files you don't want to be converted to $_GET['m'] value. 然后,您将需要其他规则来过滤掉不想转换为$_GET['m']值的文件。

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

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