[英]RewriteRule issue - modular php Bad Request
What I'm ultimately looking to do is do /about instead of /main.php?p=about. 我最终希望做的是/ about而不是/main.php?p=about。 I've seen a few posts ( like this !) but none seem to work from me.
我看过一些帖子( 像这样 !),但似乎没有一个对我有用。
Firstly, I was putting the ReWrite rules in httpd.conf..is this correct? 首先,我将ReWrite规则放在httpd.conf中。这正确吗? Lots of places mention .htaccess but I didn't have that file in any directory that seems important (the only references are in phpMyAdmin).
很多地方都提到.htaccess,但是在任何看起来都很重要的目录中都没有该文件(唯一的引用在phpMyAdmin中)。 I copied the file from phpMyAdmin into htdocs and then replaced the text with a simple rule:
我将文件从phpMyAdmin复制到htdocs,然后用简单的规则替换了文本:
RewriteEngine on
RewriteRule home main.php [L]
However localhost/home reported a Bad Request. 但是localhost / home报告了错误的请求。
So firstly which file should I use & if .htaccess where should I put the file & do I have to reference it in any other files? 因此,首先我应该使用哪个文件,如果是.htaccess,我应该在哪里放置文件,并且必须在其他任何文件中引用它吗? Secondly, is the following likely to work for my desired approach?
其次,以下内容是否可能适用于我想要的方法?
RewriteEngine on
RewriteRule ^([^/]+)/? main.php?p=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Thanks for any clarity & help. 感谢您的澄清和帮助。 Mike
麦克风
You actually have conditions ( RewriteCond
) after RewriteRule
. 您实际上在
RewriteRule
之后有条件( RewriteCond
)。 It should be other way round. 它应该是相反的方式。
Enable mod_rewrite
and .htaccess
through httpd.conf
and then put this code in your DOCUMENT_ROOT/.htaccess
file: 通过
httpd.conf
启用mod_rewrite
和.htaccess
,然后将此代码放入DOCUMENT_ROOT/.htaccess
文件中:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /main.php?p=$1 [L,QSA]
RewriteRule ^home/?$ main.php [L,NC]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.