Forum Moderators: phranque

Message Too Old, No Replies

htaccess for redirecting pages on my site

         

ivanvias

12:23 am on May 12, 2015 (gmt 0)

10+ Year Member



Hi,

I have some pages on my site that I want to redirect. However I still have some issues


https://example.com/first-lastname-word1-word2/biography/firstnamelastname
https://example.com/first-lastname-word1-word2/activity/firstnamelastname
https://example.com/first-lastname-word1-word2/announcements/firstnamelastname
https://example.com/first-lastname-word1-word2/wall/firstnamelastname


I used this rule which does the trick however i have other urls that it affects.

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/(videos|images|memorial-photos)/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^[^/]+/([^/]+/[^.]+)$ /$1 [L,NE,R=301]



For my other urls such as :
https://example.com/memorial-photos/category/3064/tylernickelson

It would write it as https://example.com/category/3064/tylernickelson

I would not like this to happen. I am already preventing it from urls like

https://example.com/videos/video/tylernickelson

[edited by: Ocean10000 at 2:41 am (utc) on May 12, 2015]
[edit reason] fixed accidential links [/edit]

lucy24

3:14 am on May 12, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



/first-lastname-word1-word2/biography/firstnamelastname

Is it always in that form? Then why doesn't the pattern reflect that?
^\w+-\w+-\w+-\w+/ etcetera

The target of a redirect should always give the full protocol-plus-domain. Otherwise you risk a double redirect. There's no earthly reason for the [NE] flag; that's only needed when the target includes something that would otherwise be percent-encoded, such as when you want to send a # fragment back to the browser.

What's the -f test for? Write your rule so it only matches URLs that will, in fact, be redirected; -f and its relatives are horribly inefficient tests. Since the rule is only intended for pages, the -d test isn't needed at all.