简体   繁体   English

HTAccess ModRewrite无法用于目录到文件

[英]HTAccess ModRewrite not working for directory to file

I'm trying to create a rewrite rule in htaccess to point a directory at a file, I keep getting 404 errors in return. 我试图在htaccess中创建一个重写规则,以将目录指向文件,但我不断收到404错误。 I should mention, the main site is a wordpress site and I'm trying to redirect one of it's url's internally for a page with a trailing folder to another url. 我应该提到,主站点是一个wordpress站点,我正在尝试将内部的URL之一内部重定向到带有尾随文件夹的页面到另一个URL。

For instance, this is the url for the wordpress page: 例如,这是wordpress页面的URL:

/homes-for-sale-details/4420/217007490/177/

The landing page I'm trying to create within that url is: 我要在该网址中创建的目标网页是:

/homes-for-sale-details/4420/217007490/177/Fb-landing-page

So I did this: 所以我这样做:

RewriteRule /homes-for-sale-details/4420/217007490/177/Fb-landing-page/(.*)$ /propertylisting1/index.php?success=$1

No go, I get a 404 error in return. 不行,我得到404错误作为回报。 The wordpress page still work, but this won't. wordpress页面仍然有效,但是不会。

Right now this new rule is placed after wordpress' own rewrite: 现在这个新的规则放在 WordPress的自己改写:

RewriteRule . /index.php [L]

I've also tried placing it before wordpress' rewrite and it breaks all my wordpress pages. 我也曾尝试将其放置在wordpress重写之前,这会破坏我所有的wordpress页面。

I had it in the wrong place, after much testing I found out if I place this rewrite before the RewriteCond statements, it works, and it doesn't brake other Wordpress rewrites. 经过大量测试后,我发现它放置在错误的位置,我发现是否将此重写放置在RewriteCond语句之前,它可以正常工作,并且不会阻止其他Wordpress重写。

So the final is: 所以最后是:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

RewriteRule ^homes-for-sale-details/4420/217007490/177/Fb-landing-page(.*)$ propertylisting1/index.php?success=$1

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

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

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