Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need to use the following redirect on my site:

RewriteEngine on
RewriteCond %{HTTP_HOST} name.com
RewriteCond %{REQUEST_URI} ^/(1[0-9]{3}|200[0-9]|201[0-3]) 
RewriteCond %{REQUEST_URI} !/2013/12 
RewriteRule ^([0-9]{4})/([0-9]{2})/(.*)$  http://v2.name.com/$1/$2/$3 [NC,R=301]

However, it only works if I delete the code Wordpress put in my .htaccess (I've tried putting it both before and after this code with no luck):

# 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

What sort of problems is this going to cause if I delete it permanently? And is there some way around this?

share|improve this question
    
Does it work if you only have one RewriteEngine On statement in .htaccess? –  Pat J Dec 10 '13 at 19:56
    
No, it doesn't seem like it changed anything. –  handsofblue Dec 10 '13 at 20:48
    
One more thing you can try -- in your first code block, change [NC,R=301] to [NC,R=301,L]. (That should tell the rewrite module that this is the last RewriteRule for the preceding RewriteConds.) –  Pat J Dec 10 '13 at 20:56
    
Holy crap that did it. Thank you so much! –  handsofblue Dec 10 '13 at 21:10
    
OK, I'll add it as an answer. –  Pat J Dec 10 '13 at 21:11

4 Answers 4

up vote 1 down vote accepted

Adding the [L] flag to the [NC,R=301] piece (ie, [NC,R=301,L]), which tells the RewriteEngine that the RewriteRule is the last one for the block of RewriteConds, apparently solved the problem.

RewriteEngine on
RewriteCond %{HTTP_HOST} name.com
RewriteCond %{REQUEST_URI} ^/(1[0-9]{3}|200[0-9]|201[0-3]) 
RewriteCond %{REQUEST_URI} !/2013/12 
RewriteRule ^([0-9]{4})/([0-9]{2})/(.*)$  http://v2.name.com/$1/$2/$3 [NC,R=301,L]

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

Reference

share|improve this answer

.htaccess rules generated by WordPress serve to make it handle arbitrary links (other than those to existing files), which in practice means that they are needed for pretty permalinks functionality.

Without them WP will function, however pretty permalinks feature won't be available and any existing pretty permalinks will be broken.

share|improve this answer
    
Well that doesn't sound good. Is there some other way I can get URL redirect to work then, or does Wordpress just thwart any attempts at redirects beyond what it already does? –  handsofblue Dec 10 '13 at 19:22
    
@frodob I rarely deal with these rules to say what might be the issue with one you are trying to add. It should be very possible in principle, since for example static page caching plugins add very extensive rules of their own. –  Rarst Dec 10 '13 at 19:41

Yes. Deleting the code may cause infinite looping.

share|improve this answer
    
This is a little too short for an answer. Please elaborate why and how would that be an issue. –  Rarst Dec 10 '13 at 19:02
    
Sorry Rarst! I dont know how to explain the "why", I just know from trial and error that looping may occur. –  Aliyah Dec 10 '13 at 19:10
    
Then the nice start would be to say that it is from your experience and describe said experience. For example it's not even clear what kind of looping you refer to. Looping in PHP code? Looping in HTTP redirects? And so on. –  Rarst Dec 10 '13 at 19:12
1  
You are correct. I'll research and then update my respponse. –  Aliyah Dec 10 '13 at 19:15

If you don't use permalinks feature then deleting .htaccess file will not cause any problem.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.