简体   繁体   English

Apache2-友好的URL

[英]Apache2 - Friendly URLs

I am using this code for creating friendly urls: 我正在使用以下代码创建友好的网址:

rewriteengine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

It should work so I could go to http://www.mywebsite.com/test but when I go my url it just says 404 Not Found but no error presents in the log file. 它应该可以工作,所以我可以去http://www.mywebsite.com/test,但是当我进入自己的网址时,它只会显示404 Not Found但是日志文件中没有错误。

I am using Apache2 on Debian x86_64 and my question is do I need to change any settings for friendly urls to work? 我在Debian x86_64上使用Apache2,我的问题是是否需要更改任何设置才能使友好的url正常工作?

There are many possibilities. 有很多可能性。 Here are a few (some of them from SmartWebDeveloper.com ): 以下是其中一些(其中一些来自SmartWebDeveloper.com ):

  • Make sure the .htaccess file is named correctly. 确保.htaccess文件的名称正确。 Make sure you didn't forget the . 确保您没有忘记. at the beginning, and that the file name is all lowercase. 开头,文件名全部为小写。

  • Make sure AllowOverride is set properly. 确保AllowOverride设置正确。 If you look in your config files ( httpd.conf , and possibly other configuration files in the /etc/apache2/ directory), you may see a line like this: AllowOverride None . 如果查看配置文件( httpd.conf ,还可能查看/etc/apache2/目录中的其他配置文件),则可能会看到如下一行: AllowOverride None That line prevents your .htaccess file from changing things. 该行阻止您的.htaccess文件进行更改。 (Note that this line may be present in the server configuration in multiple places - including the main configuration, the web root directory configuration (probably in /etc/apache2/sites-available/default ), and any VHost configuration files in the sites-enabled folder, so you need to find the one that is actually going to change things for this site.) Change it to AllowOverride FileInfo (if all you need is rewrites) or AllowOverride All (if you plan to use your .htaccess for other things.) A full description of AllowOverride is at http://httpd.apache.org/docs/current/mod/core.html#allowoverride (请注意,这条线可能存在于多个地方的服务器配置-包括主要配置,Web根目录配置(可能是/etc/apache2/sites-available/default ),并在任何虚拟主机配置文件sites-enabled文件夹,因此您需要找到一个实际上将要对此站点进行更改的文件夹。)将其更改为AllowOverride FileInfo (如果您需要重写的AllowOverride All )或AllowOverride All (如果您计划将.htaccess用作其他内容) 。) AllowOverride的完整说明位于http://httpd.apache.org/docs/current/mod/core.html#allowoverride

  • Make sure the rewrite module is enabled. 确保已启用重写模块。 If your rewrite configuration is enclosed in <IfModule mod_rewrite.c> and </IfModule> tags, or if your Apache is configured not to report .htaccess errors, you will not see anywhere that the module is disabled. 如果您的重写配置包含在<IfModule mod_rewrite.c></IfModule>标记中,或者如果Apache配置为不报告.htaccess错误,则在任何禁用该模块的地方都看不到。 To enable it, use a2enmod rewrite and restart your Apache server. 要启用它,请使用a2enmod rewrite并重新启动Apache服务器。

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

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