简体   繁体   English

需要有关.htaccess重新写入规则的帮助

[英]Need help with .htaccess ReWrite rules

I'm using Wordpress and have the following pemalink /%category%/%postname% . 我正在使用Wordpress,并具有以下pemalink /%category%/%postname% This gives me user friendly URLs like http://www.example.com/something/ . 这为我提供了用户友好的URL,例如http://www.example.com/something/

With this permalink, I will not be able to access php files directly, eg http://www.example.com/something/myfile.php . 有了这个固定链接,我将无法直接访问php文件,例如http://www.example.com/something/myfile.php

I need to write a ReWrite rule which allows me access to /include/myfile.php . 我需要编写一个ReWrite规则,该规则允许我访问/include/myfile.php Can some help me please? 能帮我一下吗? :) :)

Here's my current .htaccess file: 这是我当前的.htaccess文件:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myblogdirectory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /myblogdirectory/index.php [L]
</IfModule>
# END WordPress

Update 更新资料

Ok, I got it working. 好吧,我知道了。

I was doing it wrong from the start. 我从一开始就做错了。 I was using the "virtual" path instead of the physical path. 我使用的是“虚拟”路径,而不是物理路径。

Instead of /mysite/includes/myfile.php, I have to use /wp-content/themes/mytheme/include/myfile.php 我必须使用/wp-content/themes/mytheme/include/myfile.php而不是/mysite/includes/myfile.php

I could probably also have added RewriteCond %{REQUEST_URI} !myfile.php, which would have excluded myfile.php from the rewrite rules. 我可能还已经添加了RewriteCond%{REQUEST_URI}!myfile.php,它将在重写规则中排除myfile.php。 I have not tested this though. 我还没有测试过。

Well, your rewrite rules looks good. 好吧,您的重写规则看起来不错。

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

means that /blog/index.php won't be serverd if %{REQUEST_FILENAME] is a physical file or directory. 表示如果%{REQUEST_FILENAME]是物理文件或目录,则/blog/index.php将不会被服务器化。

More info here . 更多信息在这里

Are you sure that you're using the correct file paths? 您确定使用正确的文件路径吗?

The file you want to request should be located in /blog/include/myfile.php. 您要请求的文件应该位于/blog/include/myfile.php中。

Check your error.log for apache for any related messages. 检查您的error.log以获取有关任何相关消息的apache。

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

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