Forum Moderators: phranque

Message Too Old, No Replies

Redirecting by IP trouble.

redirecting by ip redirect loop wordpress

         

gregmcdonald

11:33 pm on Jul 20, 2012 (gmt 0)

10+ Year Member



Running WordPress, I am trying to prevent access to pages and folders that are otherwise meaningless for people to access. I’ve been trying to accomplish this for the past 2 weeks and lacking the knowledge of how to setup an .htaccess file I have failed. Many tutorials either half work or throw me into a redirect loop. I think the problem is in the ways I have tried structuring the conditions and rules as I’m unaware of how it's supposed to look.

How do I accomplish the following given the .htaccess file I’m currently working with?
  • Redirect [folder/file] located in [root] by [IP] to [root].
  • Redirect [folder/file] located in [root] to [root].
  • Redirect [folder/file] located in [subdirectory] to [root].

Questions
  • If I set a folder to redirect, but that folder contains an image, will that image still be served in a web page if the browser requests it.
  • When redirecting a folder does it redirect all child folders and files it contains if you try to access it?

.htaccess (mod_rewrite is enabled)
# 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

Also, any literature that you can link me to would be greatly appreciated.

lucy24

3:14 am on Jul 21, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Quick answer: It Depends.

Dump the <IfModule...> envelope. You either have access to mod_rewrite or you don't. If you don't, change hosts ;)

If I set a folder to redirect, but that folder contains an image, will that image still be served in a web page if the browser requests it.

It depends, first, on how tightly constrained your RewriteRule is. If it's written to capture only requests for pages or directories, then requests for images will be unaffected.

It depends, second, on where the images live.

It depends, third, on how the page code calls the images. Do you use site-absolute links like <img src = "/images/blog/picname.jpg"> or relative links like <img src = "images/picname.jpg">

:: pause here for argument about which format is appropriate ::

Robots request images in isolation, using whatever address they've already got. Browsers request images after they have already downloaded the page. That's why the link format makes a difference.

When redirecting a folder does it redirect all child folders and files it contains if you try to access it?

It depends on how the Redirect rule is written. If you were using mod_alias (Redirect by that name) -- which you're not -- then any rule naming a folder would normally apply also to everything inside the folder, because mod_alias only changes what you've told it to change and then reappends the rest of the path.

In mod_rewrite, the biggest variable is the anchor. If you say
RewriteRule directoryname/$ et cetera

then only the directory's index page will be affected. If you say
RewriteRule directoryname/filename\.html et cetera

then only pages at the top level of the directory will be affected. If you say
RewriteRule directoryname/(filename\.html)?$

then the rule will apply to the index file and all top-level named pages. If you say
RewriteRule directoryname/ http://www.example.com/otherdirectory/ et cetera

then everything in the directory will be redirected (or rewritten) to the same place. If you say
RewriteRule directoryname/(.*) http://www.example.com/otherdirectory/$1 et cetera

then everything in the old directory will be sent to the equivalent place in the new directory.

There are more permutations, but the cat is sitting on my arms.

Hence: "It depends". ;)