0

I'm gradually restructuring my site's URLs.

I have a group of old URLs with patterns like this:

mt-14_21-28
mt-15_26-hasta-16_04a
mc-01_21-28
lc-07_36-50-y-lc-08_01-03
lc-09_28-36
lc-22_14-71-y-23_01-56
jn-18_01-hasta-19_42
... there are other patterns

The idea is to create a redirect that does the following:

  1. Determine if the URL starts with mt-, mc-, lc-, or jn-
  2. If so, change all _ in that URL to - and also add the bibla/evangelios/ prefix.
  3. Alternatively, for mt-, add san-mateo, for mc-, add san-marcos, for lc-, add san-lucas, and for jn-, add san-juan.

For example:

biblia/evangelios/san-mateo/mt-14-21-28
biblia/evangelios/san-mateo/mt-15-26-hasta-16-04a
biblia/evangelios/san-marcos/mc-01-21-28
biblia/evangelios/san-lucas/lc-07-36-50-y-lc-08-01-03
biblia/evangelios/san-lucas/lc-09-28-36
biblia/evangelios/san-lucas/lc-22-14-71-y-23-01-56
biblia/evangelios/san-juan/jn-18-01-hasta-19-42

I've tried this, but it doesn't work.

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteRule ^(jn|mt|mc|lc)-([a-z0-9-]*)_{1}([a-z0-9_.-]*)$ /$1-$2-$3 [N]

    RewriteRule ^jn-(.*)$ /biblia/evangelios/san-juan/jn-$1 [R=301,L]
    RewriteRule ^mt-(.*)$ /biblia/evangelios/san-mateo/mt-$1 [R=301,L]
    RewriteRule ^mc-(.*)$ /biblia/evangelios/san-marcos/mc-$1 [R=301,L]
    RewriteRule ^lc-(.*)$ /biblia/evangelios/san-lucas/lc-$1 [R=301,L]
</IfModule>

Is there a way to do this via .htaccess, considering I don't have administrator access to that server?

9
  • What do you mean by "doesn't work" exactly? An error? Incorrect redirect? Nothing? From what you have posted something should happen. Test with 302 (temp) to avoid caching issues. Remove the <IfModule> wrapper. What version of Apache (or LiteSpeed??) are you on? Commented Sep 9 at 22:34
  • Also, what other directives do you have in your .htaccess file and where in relation to the existing directives have you placed the above code? (And make sure all caches are cleared before testing.) Commented Sep 9 at 22:47
  • @MrWhite I've removed the <IfModule> and used 302, but it doesn't work, it dos nothing. I can't see the Apache version, the httpd -v command doesn't work (shared hosting) . Commented Sep 9 at 22:53
  • @MrWhite I have several rules, but I've put these at the end of the file, to make sure they don't get overwritten. Commented Sep 9 at 23:00
  • 1
    You are absolutely right, @MrWhite. By putting the rules at the beginning of the .htaccess the redirection occurs, however, the replacement of the _ with - is not done. For example, I get: biblia/evangelios/san-mateo/mt-14_21-28 instead of biblia/evangelios/san-mateo/mt-14-21-28. Commented Sep 10 at 8:58

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.