[英]Using rewrite mod in .htaccess
I'd like to write a rewrite rule to do the following: if any of the following files exist on the server as a static html file in a specific directory then I'd like .htaccess to serve that static file. 我想编写一个重写规则来执行以下操作:如果服务器上以下任何文件作为静态html文件存在于特定目录中,则我希望.htaccess服务该静态文件。 Otherwise, I'd like the id ( first number after the .com/ and before the first hyphen ) to be passed as a query parameter to
www.gallery.com/index.php
否则,我希望将id( .com /之后和第一个连字符之前的第 一个数字 )作为查询参数传递给
www.gallery.com/index.php
Redirect should occur for the following URLs if it doesn't exist as a static HTML page. 如果以下URL不作为静态HTML页面存在,则应进行重定向。
www.gallery.com/2-swimming.html
www.gallery.com/2
gallery.com/2
Below is my entire .htaccess file 以下是我的整个.htaccess文件
<Files .htaccess>
order allow,deny
deny from all
</Files>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENANE} !-f
RewriteCond %{REQUEST_FILENANE} !-d
RewriteRule ^([0-9]+)-(.*)\.html$ /index.php?id=$1 [L]
</IfModule>
Is there anything wrong with my rewrite condition.(I'm having a hard time). 我的重写条件有什么问题。(我很难过)。 Also what is an efficient way to grab the id incase of a redirect.
还有一种在重定向的情况下获取ID的有效方法。
Why not just always pass everything to index.php
? 为什么不总是将所有内容都传递给
index.php
呢?
PHP is a lot better at manipulating strings than .htaccess
PHP在处理字符串方面比
.htaccess
更好。
The -f
line already takes care of existing static files. -f
行已经处理了现有的静态文件。 (And -d
for directories) (对于目录,则为
-d
)
RewriteRule ^(.*)$ /index.php?id=$1 [L,QSA]
This rule matches and captures everything. 此规则匹配并捕获所有内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.