简体   繁体   English

mod_rewrite添加完整目录

[英]mod_rewrite adding full directory

I have a .htaccess file to control my Apache server. 我有一个.htaccess文件来控制我的Apache服务器。 After turning RewriteEngine On, I have a rewrite rule which works properly: 开启RewriteEngine后,我有一条重写规则可以正常工作:

RewriteRule ^display\.php/([a-zA-Z0-9-z\-]+)$ "https://pastelink.net/display?q=$1" [R=301,L]

On the next line I am trying to add another rule in, to redirect sitemap.xml to sitemap.php. 在下一行中,我尝试添加另一个规则,以将sitemap.xml重定向到sitemap.php。

I have tried both: 我都尝试过:

RewriteRule ^sitemap.xml$ "https://pastelink.net/sitemap.php" [R=301, L]

and

RewriteRule ^sitemap.xml sitemap.php [R=301, L]

As well as other combinations including or omitting ^ $ and the flags. 以及其他组合,包括或省略^ $和标志。 The result each time is a rewrite to this: 每次的结果都是对此的重写:

https://pastelink.net/home/pastelin/public_html/sitemap.php

when my intention is this: 当我的意图是:

https://pastelink.net/sitemap.php

Why are these extra directories added into the URL? 为什么将这些额外的目录添加到URL中? I can't see why it would behave differently to the first rewrite rule. 我看不出为什么它的行为与第一个重写规则不同。 I can post the entire .htaccess file if that helps, though the L flag should make the code that follows irrelevant. 如果有帮助,我可以发布整个.htaccess文件,尽管L标志应该使后面的代码无关紧要。

You don't need http:// for silent rewrite rules. 您不需要http://获得无声重写规则。 Keep your root .htaccess as this: 保持根.htaccess如下:

RewriteEngine On
RewriteBase /

RewriteRule ^display\.php/([\w-]+)/?$ https://pastelink.net/display?q=$1 [R=301,L,QSA,NC]
RewriteRule ^sitemap\.xml$ sitemap.php [NC,L]

You should clear browser cache before testing these changes. 在测试这些更改之前,您应该清除浏览器缓存。

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

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