简体   繁体   中英

Struggling with Apache .htaccess RewriteRule

I am currently redoing one of my sites in Wordpress. This installation is currently sitting in wwww.mydomain.com/wordpress while I test it.

On my main site requests come in as so: http://www.mydomain.com/index/newsid/16589/some-text-here-that-is-irrelevant

The .htaccess at http://www.mydomain.com/.htaccess currently looks like this:

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

# 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.

Essentially I want to turn this: http://www.mydomain.com/index/newsid/16589/some-text-here-that-is-irrelevant

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

They primary id here is 16589 which is a variable and can change.

Any help would be appreciated, I can do simple .htaccess files but this is beyond me.

You'll need to add some rules before your wordpress rules after you've moved your wordpress installation to your document root. You'd need to do something like this in the htaccess file in your document root:

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] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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