htaccess 301 redirect example.com/beta/xyz to example.com/xyz
I need a general rule that maps every URL in the /beta
subdirectory to the corresponding URL in the root; essentially I need to remove /beta
from all URLs.
In case it makes any difference, the URLs are dynamically开发者_如何学编程 generated by WordPress.
Currently my .htaccess
file is:
# 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
Can you tell me where to put the new lines?
Thank you!
Could you try this?
RewriteEngine On
RewriteRule ^beta/(.*)$ http://example.com/$1 [R=301,L]
Your question is not entirely clear, but I would bet that what you want is having a Wordpress installed in somedir/beta
appear in yoursite.com/ instead of yoursite.com/beta/. The rules you pasted are in somedir/beta/.htaccess
, and are the default Wordpress rules. You must leave those alone.
What you need for that is to put the following rules in the root directory, as in, somedir/.htaccess
, after changing example.com to your own domain. Your webserver first reads this root .htaccess
, and when it does, it will know to rewrite requests to /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>
More info in the Codex: https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory
精彩评论