简体   繁体   English

重定向到子目录

[英]Redirect to a subdirectory

I have a dictionary website that uses WordPress. 我有一个使用WordPress的字典网站。 Now the url for any term like "myterm" is in the form : http://domain.com/myterm . 现在,诸如“ myterm”之类的任何术语的网址都采用以下格式: http ://domain.com/myterm。 I want it to redirect to http://domain.com/definition/myterm . 我希望它重定向到http://domain.com/definition/myterm I don't know how to use regex for this kind of redirection. 我不知道如何使用正则表达式进行这种重定向。 Also some urls such as domain.com/contact-Us and domain.com/FAQ exist that i don't want to redirect to /definition/Contact-us and /definition/FAQ. 还存在一些我不想重定向到/ definition / Contact-us和/ definition / FAQ的URL,例如domain.com/contact-Us和domain.com/FAQ。 Any help? 有什么帮助吗?

Try the following in htaccess 在htaccess中尝试以下操作

RedirectMatch ^/myterm$ /definition/myterm

if myterm is a dynmic path, then you can use Regex capture group to capture the path value ,it will be saved as $1 for reuse in target path 如果myterm是动态路径,则可以使用Regex捕获组捕获路径值,该值将另存为$ 1以在目标路径中重用

 RedirectMatch ^/(.*)$ /definition/$1

To exclude specific paths from redirection, you can use 要从重定向中排除特定路径,可以使用

 RedirectMatch ^/((?!contect-us|FAQ).*)$ /definition/$1

and to negate more paths, just add them inside the capture group seperated by a pipe foo|bar|foobar. 而要取消更多路径,只需将其添加到由管道foo | bar | foobar分隔的捕获组中。

Edit : 编辑:

You also need to exclude the directory from redirect, so that it can not redirect to itself. 您还需要从重定向中排除该目录,以使其无法重定向到自身。

Try this 尝试这个

 RedirectMatch ^/((?!contect-us|FAQ|defination).*)$ /definition/$1

replace "defination" with name of your folder in pattern and target. 在模式和目标中用文件夹名称替换“ defination”。

My problem is resolved. 我的问题解决了。 I used the redirect proposed by Starkeen. 我使用了Starkeen提出的重定向。 However, not in the .htaccess file. 但是,不在.htaccess文件中。 I used Simple 301 Redirects. 我使用了简单301重定向。 It works properly without conflicting with WordPress rules. 它可以正常工作而不会与WordPress规则冲突。

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

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