简体   繁体   中英

Prevent .php files from being redirected with htaccess

Because of a node.js instance I have set up the following entry in my .htaccess file:

RewriteRule ^(.*)$ http://localhost:65432/$1 [P]

A webserver is up and running which could render PHP files. This is not possible if those are being loaded from the node.js instance. Now I want to add another rule before the proxy to compute all .php files without looping through the node.js proxy. I have tried it with

RewriteRule ^(.*).php ^(.*).php [L]

but that doesn't work. How can this problem be solved? Thanks

To use a requested URI unchanged, you must use a - (dash)

- (dash)
A dash indicates that no substitution should be performed (the existing path is passed through untouched). This is used when a flag (see below) needs to be applied without changing the path.

So your rule should look like

RewriteRule \.php$ - [L]

which means, when a URI ending in .php is requested, do nothing and stop further processing.

要从代理重定向中排除.php文件,可以使用以下规则

RewriteRule ((?!\.php).*)$ http://localhost/$1 [P]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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