简体   繁体   English

htaccess-删除一个特定页面的结尾斜杠

[英]htaccess - remove trailing slash for one specific page

I have a WP site, all working great. 我有一个WP网站,都工作正常。 I then have a stand alone landing page called "landing-page.php" and this is in the root directory. 然后,我有一个名为“ landing-page.php”的独立登录页面,它位于根目录中。

I need to remove the .php and the trailing slash in order for the page to load. 我需要删除.php和结尾的斜杠以加载页面。 I only want to remove the trailing slash for this specific page. 我只想删除此特定页面的结尾斜杠。 I cannot change the directory where this page is saved as I have ad campaigns that have been configured with /landing-page/ so I cannot go change these without re-approval etc 我的广告系列已使用/ landing-page /配置,因此我无法更改此页面的保存目录,因此无法在未经重新批准的情况下更改这些内容

I have the following code which kinda works BUT... I cannot access /wp-admin. 我有以下代码可以工作,但是...我无法访问/ wp-admin。

So I need the rules only to apply to this landing page: 因此,我只需要将规则应用于此目标网页:

RewriteEngine On
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteRule ^landing-page$ landing-page.php [L]


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

</IfModule>
# END WordPress

Please help... thanks 请帮忙...谢谢

Do you mean to get rid of this line: 您是要摆脱这一行吗?

RewriteRule ^(.*)/$ /$1 [L,R=301]

and change the next line to: 并将下一行更改为:

RewriteRule ^landing-page/?$ landing-page.php [L]

?

Not sure what the problem is, but the first line is probably the problem because it's matching everything with a trailing slash. 不确定是什么问题,但是第一行可能是问题所在,因为它使所有内容都带有斜杠。 But if you want to canonicalize the trailing slash, just make it match landing-page specifically: 但是,如果您想规范化斜杠,只需使其与landing-page特别匹配:

RewriteRule ^landing-page/$ /landing-page [L,R=301]

Replace your top 2 rules with this: 以此替换您的前2条规则:

RewriteRule ^(landing-page)/$ /$1 [NC,L,R=301]
RewriteRule ^landing-page$ landing-page.php [L,NC]

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

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