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_articulo.php?Redes-sociales-2

What I’m trying to do is:
http://mundoregio.com/accesando/ver_articulo-Redes-sociales-2 (remove.php?)

or:
http://mundoregio.com/accesando/ver_articulo.php-Redes-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

I’m trying something like this:

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

Thanks for the help & guidence

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:

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

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

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


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!

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

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

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.
  1. 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:


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!

Off Topic:

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

Regards,

DK