简体   繁体   English

与Apache .htaccess RewriteRule斗争

[英]Struggling with Apache .htaccess RewriteRule

I am currently redoing one of my sites in Wordpress. 我目前正在Wordpress中重做我的一个网站。 This installation is currently sitting in wwww.mydomain.com/wordpress while I test it. 我进行测试时,此安装当前位于wwww.mydomain.com/wordpress中。

On my main site requests come in as so: http://www.mydomain.com/index/newsid/16589/some-text-here-that-is-irrelevant 在我的主要网站上,请求是这样发送的: http : //www.mydomain.com/index/newsid/16589/some-text-here-that-is-relevant

The .htaccess at http://www.mydomain.com/.htaccess currently looks like this: 位于http://www.mydomain.com/.htaccess的.htaccess当前看起来像这样:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule index/newsid/(.*) index.php?newsid=$1
RewriteEngine On

My Wordpress .htaccess currently sitting at www.mydomain.com/wordpress/.htaccess is as follows 我目前位于www.mydomain.com/wordpress/.htaccess的我的Wordpress .htaccess如下

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>

# END WordPress

When I migrate my site all links from other sites are going to break, I have incorporated all the articles elsewhere in an archive in a forum. 当我迁移网站时,来自其他站点的所有链接都将断开,我已将所有文章合并到论坛的存档中的其他位置。 I need to effectively do two things, make my .htaccess work on the root of my site for wordpress after moving it AND redirect any newsid requests elsewhere. 我需要有效地做两件事,将我的.htaccess文件移动到我网站的根目录后,然后将其重定向到其他地方。

Essentially I want to turn this: http://www.mydomain.com/index/newsid/16589/some-text-here-that-is-irrelevant 从本质上讲,我想转一下: http : //www.mydomain.com/index/newsid/16589/some-text-here-that-is-relevant

Into: http://www.mydomain.com/forums/index.php?showtopic=16589 进入: http : //www.mydomain.com/forums/index.php? showtopic= 16589

They primary id here is 16589 which is a variable and can change. 它们的主要ID在这里是16589,它是一个变量,可以更改。

Any help would be appreciated, I can do simple .htaccess files but this is beyond me. 任何帮助将不胜感激,我可以做简单的.htaccess文件,但这超出了我的范围。

You'll need to add some rules before your wordpress rules after you've moved your wordpress installation to your document root. 将wordpress安装移至文档根目录后,您需要 wordpress规则之前添加一些规则。 You'd need to do something like this in the htaccess file in your document root: 您需要在文档根目录的htaccess文件中执行以下操作:

Options +FollowSymLinks
RewriteEngine on

# redirect your newsid
RewriteRule ^index/newsid/([0-9]+)/ /forums/index.php?showtopic=$1 [L,QSA,R]

# here are the wordpress rules

# 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

If you want 301 redirects instead, replace the [L,QSA,R] with [L,QSA,R=301] . 如果要改为301重定向,则将[L,QSA,R]替换为[L,QSA,R=301]

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

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