Forum Moderators: phranque

Message Too Old, No Replies

.htaccess proper format

         

Daisy Michael

8:32 am on Apr 27, 2015 (gmt 0)

10+ Year Member



Hi,

I was trying to setup a redirect on a sub page but somewhat I'm unable to get the things right! :(

Please help for the following case:

Redirect 301 /desktop-pcs/ http://www.example.com/desktop-pcs.html (works fine)

Doing so makes the pages under this folder as http://www.example.com/desktop-pcs.htmlcore-i7-pcs.html (how can I fix such issues).

Looking forward for a timely response!

Cheers!

[edited by: phranque at 8:59 am (utc) on Apr 27, 2015]
[edit reason] exemplified URLs [/edit]

phranque

9:07 am on Apr 27, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, Daisy Michael!


that is the normal behavior for the Redirect directive:
Additional path information beyond the matched URL-path will be appended to the target URL.


try using RedirectMatch instead and specify an end anchor.

whitespace

10:58 am on Apr 27, 2015 (gmt 0)

10+ Year Member Top Contributors Of The Month



What is the intended output? Do you want all URLs within that folder (ie. that start with that folder name) to be redirected to a single file? Or only requests for the bare folder (with a slash suffix?) to be redirected?

Daisy Michael

3:46 pm on Apr 27, 2015 (gmt 0)

10+ Year Member



I have similar scenarios on a few places of my website.
Looking for something that can help me sort it out (basically we have make some updates to our website & the structure has been changed).

lucy24

4:59 pm on Apr 27, 2015 (gmt 0)

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



Yup, time for a chorus of
I really hate this damned machine
I wish that they would sell it
It never does quite what I want
But only what I tell it.


Are you looking for something that will redirect
/oldplace/ >> /newplace/
/oldplace/page1 >> /newplace/page1
/oldplace/page2 >> /newplace/page2
/oldplace/subdir/page >> /newplace/subdir/page

Or something that will only take
/oldplace/ >> /newplace/
without touching
/oldplace/blahblah >> no change
?

Weird but true, the solution is almost identical either way. But a simple Redirect can't do it. Depending on what else is going on in your htaccess, you'll need to use either RedirectMatch (mod_alias) or RewriteRule (mod_rewrite).

:: insert Why We Make You Do It Yourself* boilerplate here ::


* This really exists in my /boilerplate/ directory, though I hardly ever quote it.

Daisy Michael

3:43 pm on Apr 28, 2015 (gmt 0)

10+ Year Member



@Lucy24:

Yea, I'm looking for something like:

/oldplace/ >> /newplace/
/oldplace/page1 >> /newplace/page1
/oldplace/page2 >> /newplace/page2
/oldplace/subdir/page >> /newplace/subdir/page

OK, I'm going to try out a few things & will update the outcome.

phranque

7:31 pm on Apr 28, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



/oldplace/ >> /newplace/

Redirect 301 /desktop-pcs/ http://www.example.com/desktop-pcs.html


these examples/patterns are inconsistent.
this is not a direct-to-directory Redirect.