简体   繁体   English

我们可以使用httpd.conf代替.htaccess以获得干净的URL吗?

[英]Can we use httpd.conf instead of .htaccess for clean URL?

I have read that setting changes in httpd.conf are much better as compared to making changes in .htaccess as the later one is parsed at Runtime while .conf is parsed at the time of starting Apache. 我已经读到,与在.htaccess中进行更改相比,在httpd.conf中进行设置更改要好得多,因为后者是在运行时解析的,而.conf是在启动Apache时进行解析的。 So, is it possible to have all the .htaccess functionality in httpd.conf or there are a few things that have to done in .htaccess only. 因此,是否有可能在httpd.conf中具有所有.htaccess功能,或者仅在.htaccess中有一些事情要做。

Also, can you suggest how to debug clean URL issues? 另外,您能否建议如何调试干净的URL问题?

Basically, I am not able to get the clean URL working. 基本上,我无法使干净的URL工作。 I can access the show.php file but am not able to access the GET variables. 我可以访问show.php文件,但不能访问GET变量。 Here is the .conf settings. 这是.conf设置。

RewriteEngine On
RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/show/([^/\.]+)/([^/\.]+)         http://www.example.com/show.php?id=$1&img=$2 [L,R]

I have also added 我也加了

Options Indexes MultiViews FollowSymlinks
AllowOverride All

in <Directory "/var/www/html"> <Directory "/var/www/html">

Thanks. 谢谢。

As stated in the Apache manual on .htaccess , anything you can put in an .htaccess file can be put inside a <Directory> block within httpd.conf for better efficiency. Apache手册有关.htaccess所述 ,可以将任何可以放在.htaccess文件中的内容放在httpd.conf<Directory>块中,以提高效率。

As for your issues with rewriting the URL, your first RewriteCond appears to only be matching URLs that aren't www.example.com (the ! in front is a negation modifier). 至于您重写URL的问题,您的第一个RewriteCond似乎只是与非www.example.com匹配的URL(前面的!是否定修饰符)。 Remove the ! 删除! and see if that fixes the issue. 看看是否能解决问题。 (You probably should remove the second RewriteCond as well, until you have the first one matching; otherwise, debugging problems will be more difficult.) (您可能还应该删除第二个RewriteCond ,直到获得第一个匹配;否则,调试问题将更加困难。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM