Apache重写规则适用于localhost,但不适用于服务器
I have a site that I would like to use Apache's RewriteRule to rewrite URLs. I want:
I have AMPPS installed on my Mac and I added the following lines to httpd.conf
and they work successfully:
RewriteEngine On
RewriteRule ^/p/(.*) /index.php?p=$1 [PT]
I'm trying to do the same but on my server.
And I have added the same apache code to /public_html/.htaccess
but I get the error message below:
Not Found
The requested URL /p/home was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
The exact same code works on my localhost server. Why not on my website?
我有一个网站,我想用Apache的RewriteRule来重写网址。 我想要: p>
- http://baileyseymour.com/index.php ?p = home
重写为 li> - http:/ /baileyseymour.com/p/home li>
ul>
我在Mac上安装了AMPPS,并将以下行添加到
httpd.conf 并且它们成功运行: p>
RewriteEngine On RewriteRule ^ / p /(.*)/index.php?p=$1 [PT] code > pre>
我正在尝试在我的服务器上执行相同操作。 我已将相同的apache代码添加到
/public_html/.htaccess code>但是我得到了 以下错误消息: p>
未找到 strong>
在此服务器上找不到请求的URL / p / home。\ 另外,尝试使用ErrorDocument时遇到404 Not Found错误 请求。 p> blockquote>完全相同的代码在我的localhost服务器上运行。 为什么不在我的网站上? p> div>
Can you check your remote server apache supports "AllowOverride All" ?
also try this way maybe it will help.
RewriteEngine On
RewriteRule ^p/(.*) /index.php?p=$1 [PT]
but you may have to modify $_GET['p'] properly. which will be sent only "home" part.
You need to remove the leading slash from the rewrite rule's pattern. URI's have their leading slash removed when the rewrite engine applies rules in an htaccess file.
RewriteEngine On
RewriteRule ^p/(.*) /index.php?p=$1 [PT]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.baileyseymour\.com
RewriteRule ^(.*)$ http://www.baileyseymour.com/$1 [R=301,L]
</IfModule>
.htaccess is the right place to put them and that file should be in the same directory as your default home page.