SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Mty
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question mod_rewrite adjustment

    Hello everyone,

    I've been trying and reading a lot to implement a mod_rewrite rule but still have issues with it. I hope anyone can give me a hand in order to make it work properly. Thanks in advance.

    Here's what I've:

    My current URL is:

    http://mundoregio.com/accesando/ver_...des-sociales-2

    What I'm trying to do is:
    http://mundoregio.com/accesando/ver_...des-sociales-2 (remove.php?)

    or:
    http://mundoregio.com/accesando/ver_...des-sociales-2

    All my articles will use the ver_articulo.php file so I just want to make sure I can remove the ? from the url.

    Thanks again for pointing me to the right direction!

    Jesus
    Never give up!

  2. #2
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Mty
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm trying something like this:

    RewriteRule ^accesando-([^-]*)-([^-]*)$ /accesando/ver_articulo.php?$1-$2 [R=301,L]

    Thanks for the help & guidence
    Never give up!

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,607
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    Ola Jesus!

    Welcome to SitePoint!

    First, a specification is needed whereby you specify the format of the link you wish visitors to see then the actual link required for the server to display the intended content.

    You have that with accesando/ver_articulo-Redes-sociales-2 => accesando/ver_articulo.php?Redes-sociales-2, however, I would recommend that you delete ver_articulo entirely (because it is only confusing you). Your second "new format" is worse because it introduces a wild file extension which must fail!

    Second, code the specification:

    Code:
    RewriteEngine on
    RewriteRule ^accesando/([-a-zA-Z]+)$ accesando/ver_articulo.php?$1 [L]
    Note: This only uses the latin alphabet without accent marks - if you're including those in your links, you'll need to alter the regular expression to include them, too.

    Third, you might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It's helped may members and should help you, too.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  4. #4
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Mty
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow. Thanks a lot for your help DK. I'm reading your article right now and will be back to you as finish it to see if I can finish this rewrite rule today.

    Thanks again for your help!

    Jesus
    Never give up!

  5. #5
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Mty
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi David,

    I read this section mod-rewrite Regex on your manual and checked with the code you recommend me, which seems very appropriate.

    I include the rule on my root htaccess file and test it with no luck

    and I remove it from my root htaccess file and include it on a new htaccess file inside the accesando folder with no luck as well.

    Here's a copy of my htaccess file on root with the line you suggested me and also with another condition and rule I'm using for my forums

    Code:
    RewriteEngine On
    RewriteRule ^accesando/([-a-zA-Z]+)$ accesando/ver_articulo.php?$1 [L]
    RewriteCond %{REQUEST_URI} !^/Nuevo/
    RewriteRule ./foros/([0-9]+)-[^/]+\.html  http://www.mundoregio.com/foros/showthread.php?t=$1  [L,R=301]
    Hope you don't mind to give me a hand and let me know what I'm missing, your example on the section I mention matched nicely with the things I'm trying to do and the code you showed me.

    Thanks again for your help!
    Never give up!

  6. #6
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Mty
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've been tried with this:

    RewriteRule ^accesando/([-a-zA-Z]+)$ accesando/ver_articulo.php?$1 [L]
    RewriteRule ^./accesando/([-a-zA-Z]+)$ accesando/ver_articulo.php?$1 [L]
    RewriteRule ^/accesando/([-a-zA-Z]+)$ accesando/ver_articulo.php?$1 [L]

    in my root htaccess and inside accesando folder, still with no luck

    I'm still reading
    Never give up!

  7. #7
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,607
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    Jesus,

    Two things:

    1. My first thought in reading your post #5 was that your server does not have mod_rewrite enabled. There are ways for you to check that in the tutorial so I won't continue in that vein here.

    2. You stated that this code was for a forum. That, to me, implies that there is also other mod_rewrite code at work and, because ORDER of the mod_rewrite statements is critical, you'll need to show that code (or simply insert my code above before the other code - that should give it priority and force the redirection before your other code manipulates the {REQUEST_URI} variable).

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  8. #8
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Mty
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi David, thanks for your answer.

    1. My first thought in reading your post #5 was that your server does not have mod_rewrite enabled. There are ways for you to check that in the tutorial so I won't continue in that vein here.
    Yes, my server has mod rewrite enable.


    2. You stated that this code was for a forum. That, to me, implies that there is also other mod_rewrite code at work and, because ORDER of the mod_rewrite statements is critical, you'll need to show that code (or simply insert my code above before the other code - that should give it priority and force the redirection before your other code manipulates the {REQUEST_URI} variable).
    As I understand now, the order affects the way the rewrite rules apply, that's why I put the 1st line below RewriteEngine On yours, like this:

    Code:
    RewriteEngine On
    RewriteRule ^./accesando/([-a-zA-Z0-9]+)$ http://www.mundoregio.com/accesando/ver_articulo.php?$1 [L,NC]
    RewriteCond %{REQUEST_URI} !^/Nuevo/
    RewriteRule ./foros/([0-9]+)-[^/]+\.html  http://www.mundoregio.com/foros/showthread.php?t=$1  [L,R=301]
    This should make your rule possible, correct?

    I tried with/without the . and with the / but still with no luck.

    Do you mind if I sent you a copy of my htaccess by email or private message? I know this needs to be with my organization in there.

    Thanks again for your help!
    Never give up!

  9. #9
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,607
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    Off Topic:

    Aside: More PMs relating to the lack of a key for the value $1.


    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •