Welcome to WebmasterWorld Guest from 3.93.75.242

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

.htaccess proper format

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

New User

joined:Apr 27, 2015
posts:3
votes: 0


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]

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

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11873
votes: 245


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.
10:58 am on Apr 27, 2015 (gmt 0)

Full Member

Top Contributors Of The Month

joined:Apr 11, 2015
posts: 328
votes: 24


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?
3:46 pm on Apr 27, 2015 (gmt 0)

New User

joined:Apr 27, 2015
posts:3
votes: 0


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).
4:59 pm on Apr 27, 2015 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15936
votes: 889


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.
3:43 pm on Apr 28, 2015 (gmt 0)

New User

joined:Apr 27, 2015
posts:3
votes: 0


@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.
7:31 pm on Apr 28, 2015 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11873
votes: 245


/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.