2010-12-03 123 views
2

我需要一条通用规则,将/beta子目录中的每个URL映射到根中相应的URL;基本上我需要从所有网址中删除/betahtaccess 301将example.com/beta/xyz重定向到example.com/xyz

如果它有什么不同,这些URL是由WordPress动态生成的。

目前我.htaccess文件是:

# 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 

你能告诉我在哪里把新线?

谢谢!

+0

澄清,你想如example.com/beta/abc实际上与example.com/abc相同,您是否也希望它可以浏览器重定向或仍然在浏览器的地址栏中显示测试版部分? – Ben 2010-12-03 21:12:22

回答

0

你可以试试吗?

RewriteEngine On 
RewriteRule ^beta/(.*)$ http://example.com/$1 [R=301,L] 
0

你的问题是不完全清楚,但我敢打赌,你想是有安装在somedir/beta WordPress的东西出现在yoursite.com/而不是yoursite.com/beta/。你粘贴的规则是somedir/beta/.htaccess,并且是默认的WordPress规则。你必须让他们独处。

您需要的是将以下规则放入根目录中,如somedir/.htaccess,将example.com更改为您自己的域。您的网络服务器首先读取此根目录.htaccess,当它发生时,它会知道将请求重写为/ beta。在食品

<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 
RewriteCond %{REQUEST_URI} !^/beta/ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /beta/$1 
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 
RewriteRule ^(/)?$ beta/index.php [L] 
</IfModule> 

更多信息: https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory