0

I'm trying to redirect the address
www.example.com/tops/articles/first_article
to the address
www.example.com/tops/test1.php?name=first_article

also to redirect the address
www.example.com/tops/galleries/first_gallery
to the address
www.example.com/tops/test2.php?name=first_gallery

and all other addresses like
www.example.com/tops/first_page
to
www.example.com/tops/page.php?name=first_page

The following htaccess file is giving me a redirect loop.

RewriteEngine on
Options +FollowSymLinks

RewriteRule ^/tops/articles/(.+)$  /tops/test1.php?name=$1  [L]

RewriteRule ^/tops/galleries/(.+)$  /tops/test2.php?name=$1  [L]

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule (.*)$ ./page.php?name=$1

Doe's anyone has any idea why is that? What am I doing wrong?

Thanks in advance.

2
  • please tell me what is missing so I will know for next time. Dec 3, 2012 at 18:04
  • Specially the first slash for the first subdirectory in the pattern /tops Dec 3, 2012 at 18:06

3 Answers 3

0

Does page.php exist in the root directory (or any other non /tops/ directory for that matter)?

If not, then that is probably your problem. You should change your last rule to something like:

RewriteRule ^tops/(.*)$ /tops/page.php?name=$1
2
  • the third rule works perfectly. I have no problem with it. The problem is with the first and second rules. Dec 3, 2012 at 17:53
  • @Amit Aisikowitz You can try it without the slash: ^tops/ instead of ^/tops/.
    – jeroen
    Dec 3, 2012 at 20:04
0

Well, I finally got it working.

Thought I share it so if anyone every search for this question he will find it.

Here is the code that workd:

RewriteEngine on
Options +FollowSymLinks

RewriteRule ^articles/(.+)$ ./test1.php?name=$1 [L]

RewriteRule ^galleries/(.+)$ ./test2.php?name=$1 [L]

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule (.*)$ ./page.php?name=$1 [L]

Enjoy !

0

You may try this:

RewriteEngine On
RewriteRule ^tops/articles/([a-zA-Z0-9-=_.]+)/?$   http://www.example.com/tops/test1.php?name=$1 [L]
RewriteRule ^tops/galleries/([a-zA-Z0-9-=_.]+)/?$   http://www.example.com/tops/test2.php?name=$1 [L]
RewriteRule ^tops/([a-zA-Z0-9-=_.]+)/?$   http://www.example.com/page.php?name=$1 [L]

Replace all 3 rules with these rules.

UPDATED for all characters:

RewriteEngine On
RewriteRule ^tops/articles/([^/]*)/?$   http://www.example.com/tops/test1.php?name=$1 [L]
RewriteRule ^tops/galleries/([^/]*)/?$   http://www.example.com/tops/test2.php?name=$1 [L]
RewriteRule ^tops/([^/]*)/?$   http://www.example.com/tops/page.php?name=$1 [L]

.htaccess should be in root directory If it is in /tops directory, try removing it from the pattern and the substitution URL.

6
  • this is not per my requirements. Dec 3, 2012 at 18:03
  • It is per your requirements! Dec 3, 2012 at 18:06
  • The problem is that I didn't specify my requirement as good as I should. It needs to refer all charecters instead of just the one you supplied. The other thing I had to mention is that the htaccess file is sitting under example.com/tops Dec 3, 2012 at 21:06
  • @Amit If .* is used instead of what I wrote, the slash will be included and that will not work. That's the reason to use certain characters only. Nevertheless, I can update the answer if you tell me what are the other characters you need. Thank's for the clarification anyway. Dec 3, 2012 at 21:12
  • @Amit You should move it to the root directory. You need it in the root directory for the last rule to work, unless page.php is not in the roor directory. It seems it is. Try to explain it further in the question. Dec 3, 2012 at 21:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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