Forum Moderators: phranque

Message Too Old, No Replies

Redirect to append query string to one URL

         

eleventy

2:47 pm on Aug 31, 2014 (gmt 0)

10+ Year Member



Hi all,

I need to append a query string to one specific URL. Would a redirect be the correct way to go about it?

Redirect 301 /class-schedule  http://domain.com/class-schedule?layout=weekly


But of course this results in a redirect loop.

Can anyone point me in the right direction?

phranque

8:50 pm on Aug 31, 2014 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



use mod_rewrite instead of mod_alias directives.
then you can use a rewriteCond to avoid the loop.

lucy24

12:04 am on Sep 1, 2014 (gmt 0)

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



You can use mod_alias (Redirect by that name) to redirect to an URL with a query string. BUT only mod_rewrite can check whether the query already exists. This part is essential when the URL is otherwise unchanged.

If you have existing redirects using mod_alias, you will need to convert all of them to mod_rewrite syntax. Combining mods can have unintended consequences (Apache-speak for "The world will come to an explosive end"). Conversion isn't very hard.

eleventy

11:28 am on Sep 1, 2014 (gmt 0)

10+ Year Member



Many thanks for the nudge.

This is working:

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^class-schedule/?$ http://domain.com/class-schedule?layout=weekly [L,NE,R=301]


Thanks again :)

lucy24

3:47 pm on Sep 1, 2014 (gmt 0)

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



Good to know.

You don't actually need the [NE]; that's mainly for targets containing fragment links (literal # that has to reach the browser in that form).

wilderness

4:09 pm on Sep 1, 2014 (gmt 0)

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



You don't actually need the [NE]; that's mainly for targets containing fragment links (literal # that has to reach the browser in that form).


Really?
Is it possible to redirect the SE's in such a manner?

I've multiple "literal #'s" on same pages. times multiple pages.

The SE's grab the link from a multi-page index, unfortunately and when following-up they only request the page (absent the #).

lucy24

12:05 am on Sep 2, 2014 (gmt 0)

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



Search engine robots never request fragments, since by their nature they have to get the whole page. But search engines-- at least some of them-- do index fragments. So if your relevant content is halfway down the page, the searcher may be sent directly there. This was easier to see in action just 2-3 years ago, before https google became so ubiquitous. The fragment link doesn't, of course, get sent to your server as a request. But you used to be able to see it on the referer side, where it shows the full URL-plus-fragment of the search result. (If you're checking your own logs, it will come through as %23, not #, since everything in the referer is percent-encoded at least once.)

:: detour to check something in logs ::

Yup :( The only fragment referers I can find that are even slightly recent are from other countries' googles. That doesn't mean it is no longer happening. Just that I can't see it.