简体   繁体   English

.htaccess rewriterule文件夹和文件被重写

[英].htaccess rewriterule folder and files rewrite

I have problem with my rewrite rule. 我的重写规则有问题。 I have new webpage in root/hrp. 我在root / hrp中有新的网页。 and if i open pages in that directory, then all is OK, but when i wanna surf those pages from root (without /hrp/) then is problem. 如果我在该目录中打开页面,那么一切都很好,但是当我想从根目录(不带/ hrp /)浏览那些页面时,就会出现问题。 I found some .htaccess rules and all working fine, but if i wanna execute some pdf,jpg,or php script directly, then come problem. 我发现了一些.htaccess规则,并且一切正常,但是如果我想直接执行pdf,jpg或php脚本,则会出现问题。

Options +FollowSymLinks  -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_URI} !hrp/
RewriteRule (.*) /hrp/$1  [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/hrp/index.php

RewriteRule ^(.*)$ /index.php [L]

if i put this bottom code on begining, i can open files directli, but pages don't work and vice versa 如果我将此底层代码放在开头,则可以直接打开文件,但页面不起作用,反之亦然

RewriteCond %{REQUEST_FILENAME} (/|\.php|\.html|\.htm|\.png|\.jpg|\.jpeg|\.gif|\.xml|\.rss|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
RewriteRule ^(.+)$ $1 [L]

Try adding this at the top instead: 尝试将其添加到顶部:

RewriteRule \.(php|html?|png|jpe?g|gif|xml|rss|feed|pdf|raw)$ - [L,NC]

or you can try adding this condition to your hrp rule: 或者您可以尝试将此条件添加到您的hrp规则中:

RewriteCond %{DOCUMENT_ROOT}/hrp/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/hrp/$1 -d
RewriteRule (.*) /hrp/$1  [L]

I have find solution 我有解决办法

don't rewrite this files 不要重写此文件

RewriteCond %{REQUEST_URI} !.(gif|jpg|png|ico|css|js|swf|wav|mp3|less|cur|pdf|jpeg|txt|ico|zip|gz) [NC] RewriteCond%{REQUEST_URI}!。(gif | jpg | png | ico | css | js | swf | wav | mp3 | less | cur | pdf | jpeg | txt | ico | zip | gz)[NC]

don't rewrite this folder - there i have php files, and dont rewrite this files 不要重写此文件夹-那里我有php文件,不要重写此文件

RewriteCond %{REQUEST_URI} !(folder1|folder2|file1.php|file2.php|file3.php) [NC] RewriteCond%{REQUEST_URI}!(folder1 | folder2 | file1.php | file2.php | file3.php)[NC]

all content is in "/hrp/" folder 所有内容都在“ / hrp /”文件夹中

RewriteCond %{REQUEST_URI} !hrp/ RewriteCond%{REQUEST_URI}!hrp /

RewriteRule (.*) /hrp/$1 [L] RewriteRule(。*)/ hrp / $ 1 [L]

but url don't contains "/hrp/" 但网址不包含“ / hrp /”

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

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

RewriteCond %{REQUEST_URI} !^/hrp/index.php RewriteCond%{REQUEST_URI}!^ / hrp / index.php

RewriteRule (.*) /index.php [L] RewriteRule(。*)/index.php [L]

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

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