我在.htaccess中的重写规则遇到了一些麻烦,这里没有其他答案似乎可以解决问题!
基本上下面的代码可行
RewriteRule ^index.php$ test.php但是,只要我添加任何其他内容,它就不会! 下面的两行代码根本不起作用
RewriteRule ^project-([0-9]+)\.html$ project.php?id=$1 RewriteRule ^project.php?id=82$ test.php当我开始工作时,我最终想要从页面中获取项目标题并将其插入到URL中(如果您查看URL,就像这个站点一样)并将所有.php转换为.html但我似乎已经落在第一关!
任何人的想法? 任何帮助将不胜感激!
I am having some trouble with the Rewrite rule in .htaccess and none of the other answers on here seem to do the trick!
Basically the code below works
RewriteRule ^index.php$ test.phpHowever as soon as I add anything else it does not! The two lines of code below do not work at all
RewriteRule ^project-([0-9]+)\.html$ project.php?id=$1 RewriteRule ^project.php?id=82$ test.phpWhen I get this working I eventually want to take the project title from the page and insert it in the url (just like this site if you take a look in the URL) AND turn all .php to .html but I have seem to have fallen at the first hurdle!
Any ideas anyone? Any help will be gratefully received!
最满意答案
请参阅以下对您的代码的编辑
#escape the . so it does not match indexsphp etc #added [NC,L] so it is not case sensitive and last rule processed RewriteRule ^index\.php$ test.php [NC,L] #added [NC,L] so it is not case sensitive and last rule processed # and QSA to pass through any existing query string values RewriteRule ^project-([0-9]+)\.html$ project.php?id=$1 [L,NC,QSA]如果这个规则
RewriteRule ^ project.php?id = 82 $ test.php
仅在id = 82时才匹配,那么它将无法工作,需要重写如下
#if the query string has an id=82 RewriteCond %{QUERY_STRING} id=82 [NC] #and resource is project.php, send it to test.php RewriteRule ^project\.php$ test.php [NC,L]编辑
我想采取project.php?id = 82并更改为project-82.html
请参阅以下规则
#if the original request has project.php RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /project\.php [NC] #capture the id param RewriteCond %{QUERY_STRING} id=([0-9]+) [NC] #and 301 redirect to project-id.html RewriteRule . project-%1.html? [L,R=301]See the following edits to your code below
#escape the . so it does not match indexsphp etc #added [NC,L] so it is not case sensitive and last rule processed RewriteRule ^index\.php$ test.php [NC,L] #added [NC,L] so it is not case sensitive and last rule processed # and QSA to pass through any existing query string values RewriteRule ^project-([0-9]+)\.html$ project.php?id=$1 [L,NC,QSA]If this rule
RewriteRule ^project.php?id=82$ test.php
is intended to match only when the id=82, then it will not work and needs to be re-written as follows
#if the query string has an id=82 RewriteCond %{QUERY_STRING} id=82 [NC] #and resource is project.php, send it to test.php RewriteRule ^project\.php$ test.php [NC,L]EDIT
I would like to take project.php?id=82 and change to project-82.html
See rules below
#if the original request has project.php RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /project\.php [NC] #capture the id param RewriteCond %{QUERY_STRING} id=([0-9]+) [NC] #and 301 redirect to project-id.html RewriteRule . project-%1.html? [L,R=301]更多推荐
发布评论