1

I have a folder "journals" inside my public_html.So my links are like this:

site/journals/index.php/journal1, site/journals/index.php/journal2 etc.(journal1,journal2 are just illustration.It might be technology,arts etc.)

I have(with help of Jon) .htaccess which is making site/journals/index.php/journal1 to appear as site/index.php/journal1.

But I am still able to access/view- site/journals/index.php/journal1.

I want to disable site/journals/index.php/journal1 and only site/index.php/journal1 should be visible.Please let me know how can I do that.

Please check this for more info.

Here is the existing .htaccess in root(/) folder

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/sunder
RewriteRule ^index\.php(.*)$ /sunder/index.php$1? [L]
</IfModule>
Community
  • 1
  • 1
MBanerjee
  • 207
  • 1
  • 4
  • 10

2 Answers2

0

The rules John gave you are incorrect. Let's see:

What you need is a rule to rewrite URLs like example.com/index.php/journal1 to point to /journals/index.php/journal1. Therefore, you must take care to not overdo the matching and rewriting.

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteRule ^journals/(.*)$ http://example.com/$1 [R=301,L]

    RewriteRule ^index\.php/(.*)$ /journals/index.php/$1 [L]
</IfModule>

Examples of a rewritten URLs:

example.com/index.php/journal2 => /home/bane/htdocs/journals/index.php/journal2

example.com/index.php/foo/bar  => /home/bane/htdocs/journals/index.php/foo/bar
aefxx
  • 24,835
  • 6
  • 45
  • 55
  • its not only journal1,journal2-that was an illustration.after journals/index.php,I may put different name-say technology,arts etc. – MBanerjee Oct 13 '12 at 22:14
  • Then you should take your time and improve your question, don't you think? – aefxx Oct 13 '12 at 22:20
  • "RewriteEnginge" spelling is wrong.I was unable to edit that.please correct that.And still journals/foo is accessible. – MBanerjee Oct 13 '12 at 22:32
  • How do you want to handle `journals/foo`? Forbid, redirect permanently or simply reply that the resource could not be found? – aefxx Oct 13 '12 at 23:03
  • Updated the answer. Now, every URL that starts with `/journals/` gets redirected (e.g. `/journals/bob/ross` would be redirected to `http://example.com/bob/ross`). – aefxx Oct 13 '12 at 23:16
0

I want to disable site/journals/index.php/journal1 and only site/index.php/journal1 should be visible.Please let me know how can I do that.

Since you want to disable accesses to the old URLs (while still internally rewriting them), you need to match against the actual request and not simply the URI. If you match against the URI and do a redirect, the redirect will get rewritten internally, which will match the other rule and redirect again, resulting in your browser complaining that the page isn't redirecting properly.

Try adding these rules right under the RewriteEngine On in the rules that you already have (in your question):

RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /sunder/([^\ ]+)
RewriteRule ^ /%2 [L,R=301]

This only gets applied when the actual request is for something that starts with /sunder/ and it redirects the browser to a URL with it removed.

Jon Lin
  • 142,182
  • 29
  • 220
  • 220