简体   繁体   English

不能从一个文件夹重定向(重写)到另一个文件夹

[英]No redirection (rewrite) from one folder to another folder

The full .htaccess file 完整的.htaccess文件

Following is my full htaccess file. 以下是我完整的htaccess文件。

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /

#redirect index to homepage
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

#prevent hotlinking
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?www.example.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]

#redirect galleries to portfolio
RewriteRule ^galleries/(.*)$ /portfolio/$1 [R=301,NC,L]

#prevent access to wp-config
<files wp-config.php>
 order allow,deny
 deny from all
</files>
</IfModule>

The directive in question 有问题的指令

The following one is obviously the one in question: 下面的一个显然是有问题的:

#redirect galleries to portfolio
RewriteRule ^galleries/(.*)$ /portfolio/$1 [R=301,NC,L]

Expected outcome 预期结果

If I go to http://subdomain.example.com/galleries/headshots/ the server should redirect to http://subdomain.example.com/portfolio/headshots/ 如果我转到http://subdomain.example.com/galleries/headshots/则服务器应重定向到http://subdomain.example.com/portfolio/headshots/

What happening instead 发生了什么事

Nothing at all happens, I remain on http://subdomain.example.com/galleries/headshots/ . 什么都没有发生,我仍然停留在http://subdomain.example.com/galleries/headshots/

What I have tried so far without success 到目前为止我没有成功尝试过的

I added slashes at the end of both, the source and target - nothing changed: 我在源和目标的末尾都添加了斜杠-没有改变:

#redirect galleries to portfolio
RewriteRule ^galleries/(.*)$/ /portfolio/$1/ [R=301,NC,L]

Also tried putting the directive on top, just below RewriteBase / - still no luck. 还尝试将指令放在RewriteBase /下方的RewriteBase / -还是没有运气。

Notes 笔记

Note that this happens on a subdomain (see example url), although I don't think that has an impact on this behaviour. 请注意,这发生在子域上(请参见示例url),尽管我认为这不会影响此行为。

This is happening on a Wordpress installation, but I have doubts it influences that. 这是在Wordpress安装上发生的,但是我怀疑它是否会影响安装。 All the other directives seem to work fine (react on change). 所有其他指令似乎都可以正常工作(对更改做出反应)。

Edit (from the comment reply to @Panama Jack): Both directories actually exist and are separate pages, but one is only setup as a script, if you like (other pages have to access its gallery). 编辑 (来自对@Panama Jack的评论回复):两个目录实际上都存在并且是单独的页面,但是如果您愿意的话,只能将其设置为脚本(其他页面必须访问其库)。

In your rewrite rule the URL should start with a /. 在您的重写规则中,URL应该以/开头。

Besides, the part (.*)$/ is very strange: you are first looking for anything until the end and then adding a slash. 此外, (.*)$/部分非常奇怪:您首先要查找任何内容,直到结尾,然后添加斜杠。 Did you want to limit the rewrite rules to directories? 您是否要将重写规则限制为目录? Then why not including the trailing slash in the pattern: (.*)/$ ? 然后,为什么不在模式中包含尾部斜杠: (.*)/$

The below rule would redirect everything below /galleries/ 以下规则将重定向/galleries/ 所有内容

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

Slash is in the wrong place. 斜杠在错误的位置。 Change this 改变这个

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

to this 对此

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

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

相关问题 在Wordpress问题中将图像从一个文件夹复制到另一个文件夹 - Copying images from one folder to another folder in wordpress issue 将Wordpress从一个文件夹移动到另一个文件夹 - Moving Wordpress from one folder to another htaccess重定向到特定文件夹 - htaccess redirection to particular folder 带有一个子文件夹异常的Wordpress SSL重定向 - Wordpress SSL Redirection with One Sub-Folder Exception 从重写 htaccess 中排除文件和文件夹 - Exclude file and folder from rewrite htaccess 页面转发,将URL中调用的参数从一个文件夹传输到另一个文件夹 - Page forwarding with transfer of parameters called in URLs from one folder to another Wordpress - 外部开发人员添加了这些页面文件夹 - 如何将页面从一个文件夹移动到另一个文件夹? - Wordpress - External developer added these page folders - How do I move a page from one folder to another folder? 在Wordpress中将图像从一个文件夹裁剪,调整大小并保存到另一个文件夹 - Cropping, Re-sizing and Saving images from one folder to another folder in wordpress htaccess重写规则,用于将文件夹中的所有图像复制到另一个域 - htaccess rewrite rule for all images in a folder to another domain htaccess隐式重写文件夹 - htaccess invisibly rewrite folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM