简体   繁体   English

.htaccess网址重写

[英].htaccess url rewriting

can anybody please tell me the rewrite rule so I can make a URL like this: 有人可以告诉我重写规则吗,这样我就可以创建一个URL:

http://www.mysite.com/index.php?page=directory1/page
what I'm trying to do is remove the "index.php?page=" so i get a
"http://www.mysite.com/directory1/page"

I'm assuming you are trying to bootstrap everything via the index.php file. 我假设您正在尝试通过index.php文件引导所有内容。 So try this out. 所以尝试一下。 Any file or directory that doesn't exist will be force through the index.php file. 任何不存在的文件或目录都将强制通过index.php文件。

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php

This is how Drupal does it; Drupal就是这样做的。 it's very similar to toneplex's example, but it doesn't mess around with extension checking and it adds an extra check on favicon.ico, which many browsers automatically request; 它与toneplex的示例非常相似,但是它不会与扩展名检查混在一起,并且在favicon.ico上添加了额外的检查,许多浏览器会自动请求该检查; this saves an extra hit on your PHP code if you're missing favicon.ico. 如果您缺少favicon.ico,则可以节省您的PHP代码的额外费用。

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]

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

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