PDA

View Full Version : Help with couple of mod_redirect rules


Jaffery
09-23-2015, 01:34 PM
Since, I just got rid of vbseo, now I am trying to deal with redirect as much as possible. Taking care of threads was easy however still urls like tags, attachments etc. remains.. so, I hope guys here may help me through with their wisdom in mod_rewrite rules .. regex

So, I am stuck on this.. wants to do following:

redirect:
domain.com/talk/tags/letter.html (letter is tag)

To

domain.com/talk/tags.php?tag=letter


I tried this

RewriteRule tags/([^/]+)\.html /tags.php?tag=$1 [L,R=301]

But its not working.

My forum is at :
domain.com/talk

And I am adding above rule in domain.com/talk/.htaccess with "RewriteBase /talk/" .
This is where I have added thread redirection code which works fine.

Dave
09-23-2015, 03:23 PM
Hmm it should work fine..
What if you remove the slash before tags.php in your rewrite rule?

Jaffery
09-23-2015, 06:37 PM
Hmm it should work fine..
What if you remove the slash before tags.php in your rewrite rule?

Nope its not working, and if I remove / from tags.php , it will add absolute path to the file.. but here first thing is that it should detect the rule at first place.

kh99
09-23-2015, 06:59 PM
Maybe you want [^.], like
RewriteRule /tags/([^.]+)\.html /tags.php?tag=$1 [L,R=301]


ETA: Hmm...or in case tags can show up elsewhere in the path, maybe both . and /, like
RewriteRule /tags/([^./]+)\.html /tags.php?tag=$1 [L,R=301]

Dave
09-23-2015, 07:04 PM
Could it be that an other rewrite rule is being applied before it reaches that one? Can you post all the contents of your .htaccess file?

Jaffery
09-23-2015, 09:30 PM
Maybe you want [^.], like
RewriteRule /tags/([^.]+)\.html /tags.php?tag=$1 [L,R=301]


ETA: Hmm...or in case tags can show up elsewhere in the path, maybe both . and /, like
RewriteRule /tags/([^./]+)\.html /tags.php?tag=$1 [L,R=301]


Thanks guys, it worked with following: (and yes there were some conflicting rules from default vb)


RewriteRule tags/([^.]+)\.html /talk/tags.php?tag=$1 [L,R=301]

Now I need to handle attachment urls :

Its like :
http://domain.com/members/username/albums/my-updates/2451-user-privacy-security.jpg
Here 2451 is image ID:

I did this :

RewriteRule members.+/([\d]+)-.+\.jpg http://domain.com/talk/attachment.php?attachmentid=$1 [L,R=301]


Again not working..

No matter how much I read about regex, its always confusing for me, can you guys confirm if I read it correct :

[^/] mean any character except /
so,
[^./] means any character exept . and /

am I reading it right ?

--------------- Added 1443051370 at 1443051370 ---------------

Well.. I donno but now its working .. for precaution I have added condition for attachment url redirect:

#image attachment
RewriteCond %{REQUEST_URI} /albums/ [NC]
RewriteRule members.+/([\d]+)-.+\.jpg http://domain.com/talk/attachment.php?attachmentid=$1 [L,R=301]

Is it as I think, ie. first checking condition if URI contains /albums/ word and then only proceed for further match and redirect ?

Brandon Sheley
09-23-2015, 09:49 PM
I know Joe @BirdOfPrey... oh ya,, vb doesn't do that :(

Well anyways, he helped me out tremendously with some redirects.
Maybe He'll see this thread and post.