Welcome to WebmasterWorld Guest from 54.198.52.8

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

301 Redirect for links with an # in it?

     
8:42 pm on Jan 15, 2016 (gmt 0)

Senior Member

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

joined:June 16, 2010
posts: 3823
votes: 29


How do I redirect a URL in the .htaccess file if it has an # in the URL?

/blog/old-url#California

I tried just leaving the hashtag an everything after it off something like:

/blog/old-url http://www.example.com/new-url.html

But it redicreted to a different page altogether...

Thanks in advance.
9:39 pm on Jan 15, 2016 (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:14036
votes: 522


You can't. The # is not sent to the server; it is retained by the browser for its own use. (You can include a # in the target if you use the [NE] tag. There's also some special business about !# which is not cussing but the "hashbang", widely seen a few years back. Ajax, I think. But neither of these seems to be your situation)

I tried just leaving the hashtag an everything after it off something like:
/blog/old-url http://www.example.com/new-url.html
But it redirected to a different page altogether.

Is this in htaccess (or a directory section of config)? If so, leave off the opening / in the pattern, or the rule will always fail, meaning that your "different page altogether" is coming from, er, a different rule altogether.
10:06 pm on Jan 15, 2016 (gmt 0)

Senior Member

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

joined:June 16, 2010
posts: 3823
votes: 29


Thanks Lucy:

I am a little confused though.

It's a bunch of wordpress pages I am trying to redirect, and my wordpress installation (and .htaccess file) is in the folder /blog/

For now, I can ignore the problem about someone trying to reach a URL with a # in it.

But I have another question:

" If so, leave off the opening / in the pattern, or the rule will always fail"


Do I leave off the beginning / if it is in an .htaccess file?

Or do lave off the beginning / if it is in "a directory section of config"? (whatever that means. total Mohawk for me...)

~~~~

The other problem is there is the blog's "home page" just at:

www.example.com/blog/

I want that to redirect to

www.example.com

But when i try something like:

Reirect 301 /blog/ http://www.example.com

All my OTHER pages that are redirecting get messed up. For example:

Reirect 301 /blog/old-url http://www.example.com/new-url.html

Then redirects to:

http://www.example.comhttp://www.example.com/new-url.html
10:41 pm on Jan 15, 2016 (gmt 0)

Administrator from US 

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

joined:Dec 27, 2006
posts:3451
votes: 181


Wordpress URLs don't play nice with redirect efforts. To make your blog home page show at example.com/ you need to go to the WP Settings and change it there. That will automatically change all the old example.com/blog/URLs to example.com/URLs because that's how WP creates its URLs: [settings_URL]/[page-name]

IF the WP install is in a folder (subdirectory) rather than the root directory then you would need to edit the index.php file. The details for either type of change are at the WordPress Codex site: [codex.wordpress.org...]
1:48 am on Jan 16, 2016 (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:14036
votes: 522


Do I leave off the beginning / if it is in an .htaccess file?

Always leave off the initial / unless the rule is lying loose in the config file-- and honestly I can't conceive of any situation where you'd be doing that. I mean, there's always going to be a directory, even if it's just /website/ vs. /otherstuff/

Do not repeat NOT use mod_alias (Redirect by that name) on any site that already uses mod_rewrite-- which, pretty much by definition, includes any WP install. It is also best not to use mod_rewrite in more than one directory along the same path. That means physical directory, which may be completely independent of /url/directory/

If you need to make RewriteRules that aren't covered by WordPress, make sure you put them before the #wordpress# section of the htaccess file. You will need to say "RewriteEngine on" twice, which looks silly but is otherwise harmless. It's best to make your own rules if you're up to it, because dumping everything on WP is about the most server-intensive thing you can do.
9:22 pm on Jan 16, 2016 (gmt 0)

Senior Member

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

joined:June 16, 2010
posts: 3823
votes: 29


@ not2easy

@ Lucy24


Thank you both for your help. It is MUCH appreciated!