OSX +阿帕奇2 + httpd.conf +主机 + .htaccess = 不工作

发布于 2024-11-06 09:34:12 字数 1904 浏览 4 评论 0原文

在我的 Mac 上,我尝试在本地 php 项目上激活 htaccess 重写规则。这是我的配置:

我使用 OSX 10.6.7,Apache2 正在运行,Php5 已激活。

我的项目位置:/Library/WebServer/Documents/my-project/

httpd.conf

[...]
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
DocumentRoot "/Library/WebServer/Documents"
<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Allow from all
</Directory>
<Directory "/Library/WebServer/Documents">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>
[...]

httpd-vhosts.conf

NameVirtualHost *:80
<VirtualHost *:80>
    DocumentRoot "/Library/WebServer/Documents/my-project/"
    ServerName my-project.local
</VirtualHost>

my_user_name.conf

<Directory "/Users/my_user_name/Sites/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

主机

127.0.0.1 my-project.local

*.htaccess (/Library/WebServer/Documents/my-project/.htaccess) *

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([0-9]+)\.home\.html$ front/content/home.php?rub=$1 
RewriteRule ^([0-9]+)-([0-9]+)-[a-z0-9A-Z'_%?éèàêâûô\-]+\.html$ front/content/article.php?id=$1&rub=$2 [L]
[...]

但是,当我尝试访问时:

http://my-project.local/66-75-one-great-page .html

它不会解析为:

http://my-project.local/front/content/article.php?id=66&rub=75

Rhhaaa,有什么想法吗? 谢谢你们:-)

On my Mac, I'm trying to activate htaccess rewrite rules on a local php project. Here's my configuration :

I'm using OSX 10.6.7, Apache2 is running, Php5 is activated.

My project location: /Library/WebServer/Documents/my-project/

httpd.conf

[...]
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
DocumentRoot "/Library/WebServer/Documents"
<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Allow from all
</Directory>
<Directory "/Library/WebServer/Documents">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>
[...]

httpd-vhosts.conf

NameVirtualHost *:80
<VirtualHost *:80>
    DocumentRoot "/Library/WebServer/Documents/my-project/"
    ServerName my-project.local
</VirtualHost>

my_user_name.conf

<Directory "/Users/my_user_name/Sites/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

hosts

127.0.0.1 my-project.local

*.htaccess (/Library/WebServer/Documents/my-project/.htaccess) *

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([0-9]+)\.home\.html$ front/content/home.php?rub=$1 
RewriteRule ^([0-9]+)-([0-9]+)-[a-z0-9A-Z'_%?éèàêâûô\-]+\.html$ front/content/article.php?id=$1&rub=$2 [L]
[...]

But, when I try to access :

http://my-project.local/66-75-one-great-page.html

It don't resolve as :

http://my-project.local/front/content/article.php?id=66&rub=75

Rhhaaa, any ideas ?
Thx you guys :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

聚集的泪 2024-11-13 09:34:12

您必须在重写规则中的站点名称后面包含尾部斜杠。更改重写规则如下并尝试:

RewriteRule ^/([0-9]+)\.home\.html$ front/content/home.php?rub=$1 
RewriteRule ^/([0-9]+)-([0-9]+)-[a-z0-9A-Z'_%?éèàêâûô\-]+\.html$ front/content/article.php?id=$1&rub=$2 [L]

You have to include the trailing slash after the site name in rewrite rule. Change the rewrite rule as below and try :

RewriteRule ^/([0-9]+)\.home\.html$ front/content/home.php?rub=$1 
RewriteRule ^/([0-9]+)-([0-9]+)-[a-z0-9A-Z'_%?éèàêâûô\-]+\.html$ front/content/article.php?id=$1&rub=$2 [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文