Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
improved spelling and formatting
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

I'm currently migrating a site to DrupalDrupal. The old site has thousands of dynamic urlsURLs for which i can recognize via regexI cannot use a regular expression to handle them. Those urls doesURLs exist in a slightly different form in the Drupal pageDrupal site. 
Unfortunately the urlURL structure is too complicated for beeingbeing processed direcltydirectly in ana .htaccess.htaccess file.

Now I want all the old urlsURLs to answer withreturn a 301 respond redirectingredirect to the new urlURL.

HereThis is what I tried: 1st: Implementing hook_page_preprocess() and sending an RedirectResponse to the new url if the incoming url matches my regex for the old urls.

2nd: Implementing an event subscriber that does basically the same on the onRequest event.

  • I implemented hook_page_preprocess() and sent a RedirectResponse to the new URL when the incoming URL matches the regular expression for the old URLs
  • I implemented an event subscriber that does basically the same on the onRequest event

In both the cases I send, the Redirect Respond like this:redirect response is sent with the following code.

$respond = new TrustedRedirectResponse($url,301);
$respond->send();
die();
$respond = new TrustedRedirectResponse($url,301);
$respond->send();
die();

Both solutions do work ifwhen the user is logged in-in. In my local dev envdeveloping site, it works also ifwhen the user is not logged in-in. But onOn the live server, it does notdoesn't work when the user is not logged infor anonymous users.

FunnyThe funny thing is that, even ifwhen the redirectredirection works (logged in user)for logged-in users, the Drupal log showshows a page not foundPage not found entry for that urlURL. So it seems that even with the eventsubscriberevent subscriber solution, Drupal handelsDrupal handles the 404 part first, and then executes my code.

Any ideas what I'mWhat am I doing wrong? Or suggestions how to manage what I'm trying to do
Should I implement this differently?

I'm currently migrating a site to Drupal. The old site has thousands of dynamic urls which i can recognize via regex. Those urls does exist in a slightly different form in the Drupal page. Unfortunately the url structure is too complicated for beeing processed direclty in an .htaccess file.

Now I want all old urls to answer with a 301 respond redirecting to the new url.

Here is what I tried: 1st: Implementing hook_page_preprocess() and sending an RedirectResponse to the new url if the incoming url matches my regex for the old urls.

2nd: Implementing an event subscriber that does basically the same on the onRequest event.

In both cases I send the Redirect Respond like this:

$respond = new TrustedRedirectResponse($url,301);
$respond->send();
die();

Both solutions do work if the user is logged in. In my local dev env, also if the user is not logged in. But on the live server it does not work when the user is not logged in.

Funny thing is, even if the redirect works (logged in user), the Drupal log show a page not found entry for that url. So it seems that even with the eventsubscriber solution, Drupal handels the 404 part first, and then executes my code.

Any ideas what I'm doing wrong? Or suggestions how to manage what I'm trying to do?

I'm currently migrating a site to Drupal. The old site has thousands of dynamic URLs for which I cannot use a regular expression to handle them. Those URLs exist in a slightly different form in the Drupal site. 
Unfortunately the URL structure is too complicated for being processed directly in a .htaccess file.

I want all the old URLs to return a 301 redirect to the new URL.

This is what I tried.

  • I implemented hook_page_preprocess() and sent a RedirectResponse to the new URL when the incoming URL matches the regular expression for the old URLs
  • I implemented an event subscriber that does basically the same on the onRequest event

In both the cases, the redirect response is sent with the following code.

$respond = new TrustedRedirectResponse($url,301);
$respond->send();
die();

Both solutions do work when the user is logged-in. In my local developing site, it works also when the user is not logged-in. On the live server, it doesn't work for anonymous users.

The funny thing is that, even when the redirection works for logged-in users, the log shows a Page not found entry for that URL. So it seems that even with the event subscriber solution, Drupal handles the 404 part first, and then executes my code.

What am I doing wrong?
Should I implement this differently?

Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user

redirect Redirect before 404 page

I'm currently migrating a site to drupalDrupal. The old site has thousands of dynamic urlurls which i can recognize via regex. thoseThose urls dodoes exist in a slightly different form in the drupalDrupal page. unfortunatelyUnfortunately the url structure is too complicated for beeing processed direclty in an htaccess.htaccess file.

Now I want all old urls to answer with a 301 respond redirecting to the new url.

Here is what I tried: 1st: implementing page_preprocess hookImplementing hook_page_preprocess() and sending an RedirectResponse to the new url if the incoming url matches my regex for the old urls.

2nd: implementingImplementing an event subscriber that does basically the same on the onRequest event.

In both cases I send the Redirect Respond like this:

$respond = new TrustedRedirectResponse($url,301); $respond->send(); die();

$respond = new TrustedRedirectResponse($url,301);
$respond->send();
die();

Both solutions do work if the user is logged in. In my local dev env, also if the user is not logged in. But on the live server it does not work when the user is not logged in.

Funny thing is, even if the redirect works (logged in user), the drupalDrupal log show a page not found entry for that url. So it seems that even with the eventsubscriber solution, drupalDrupal handels the 404 part first, and then executes my code.

Any ideas what I'm doing wrong? Or suggestions how to manage what I'm trying to do?

redirect before 404 page

I'm currently migrating a site to drupal. The old site has thousands of dynamic url which i can recognize via regex. those urls do exist in a slightly different form in the drupal page. unfortunately the url structure is too complicated for beeing processed direclty in an htaccess file.

Now I want all old urls to answer with a 301 respond redirecting to the new url.

Here is what I tried: 1st: implementing page_preprocess hook and sending an RedirectResponse to the new url if the incoming url matches my regex for the old urls.

2nd: implementing an event subscriber that does basically the same on the onRequest event.

In both cases I send the Redirect Respond like this:

$respond = new TrustedRedirectResponse($url,301); $respond->send(); die();

Both solutions do work if the user is logged in. In my local dev env, also if the user is not logged in. But on the live server it does not work when the user is not logged in.

Funny thing is, even if the redirect works (logged in user), the drupal log show a page not found entry for that url. So it seems that even with the eventsubscriber solution, drupal handels the 404 part first, and then executes my code.

Any ideas what I'm doing wrong? Or suggestions how to manage what I'm trying to do?

Redirect before 404 page

I'm currently migrating a site to Drupal. The old site has thousands of dynamic urls which i can recognize via regex. Those urls does exist in a slightly different form in the Drupal page. Unfortunately the url structure is too complicated for beeing processed direclty in an .htaccess file.

Now I want all old urls to answer with a 301 respond redirecting to the new url.

Here is what I tried: 1st: Implementing hook_page_preprocess() and sending an RedirectResponse to the new url if the incoming url matches my regex for the old urls.

2nd: Implementing an event subscriber that does basically the same on the onRequest event.

In both cases I send the Redirect Respond like this:

$respond = new TrustedRedirectResponse($url,301);
$respond->send();
die();

Both solutions do work if the user is logged in. In my local dev env, also if the user is not logged in. But on the live server it does not work when the user is not logged in.

Funny thing is, even if the redirect works (logged in user), the Drupal log show a page not found entry for that url. So it seems that even with the eventsubscriber solution, Drupal handels the 404 part first, and then executes my code.

Any ideas what I'm doing wrong? Or suggestions how to manage what I'm trying to do?

added 241 characters in body
Source Link

I'm currently migrating a site to drupal. The old site has thousands of dynamic url which i can recognize via regex. those urls do exist in a slightly different form in the drupal page. unfortunately the url structure is too complicated for beeing processed direclty in an htaccess file.

Now I want all old urls to answer with a 301 respond redirecting to the new url.

Here is what I tried: 1st: implementing page_preprocess hook and sending an RedirectResponse to the new url if the incoming url matches my regex for the old urls.

2nd: implementing an event subscriber that does basically the same on the onRequest event.

In both cases I send the Redirect Respond like this:

$respond = new TrustedRedirectResponse($url,301); $respond->send(); die();

Both solutions do work if the user is logged in. In my local dev env, also if the user is not logged in. But on the live server it does not work when the user is not logged in.

Funny thing is, even if the redirect works (logged in user), the drupal log show a page not found entry for that url. So it seems that even with the eventsubscriber solution, drupal handels the 404 part first, and then executes my code.

Any ideas what I'm doing wrong? Or suggestions how to manage what I'm trying to do?

I'm currently migrating a site to drupal. The old site has thousands of dynamic url which i can recognize via regex. those urls do exist in a slightly different form in the drupal page. unfortunately the url structure is too complicated for beeing processed direclty in an htaccess file.

Now I want all old urls to answer with a 301 respond redirecting to the new url.

Here is what I tried: 1st: implementing page_preprocess hook and sending an RedirectResponse to the new url if the incoming url matches my regex for the old urls.

2nd: implementing an event subscriber that does basically the same on the onRequest event.

In both cases I send the Redirect Respond like this:

$respond = new TrustedRedirectResponse($url,301); $respond->send(); die();

Both solutions do work if the user is logged in. In my local dev env, also if the user is not logged in. But on the live server it does not work when the user is not logged in.

Any ideas what I'm doing wrong? Or suggestions how to manage what I'm trying to do?

I'm currently migrating a site to drupal. The old site has thousands of dynamic url which i can recognize via regex. those urls do exist in a slightly different form in the drupal page. unfortunately the url structure is too complicated for beeing processed direclty in an htaccess file.

Now I want all old urls to answer with a 301 respond redirecting to the new url.

Here is what I tried: 1st: implementing page_preprocess hook and sending an RedirectResponse to the new url if the incoming url matches my regex for the old urls.

2nd: implementing an event subscriber that does basically the same on the onRequest event.

In both cases I send the Redirect Respond like this:

$respond = new TrustedRedirectResponse($url,301); $respond->send(); die();

Both solutions do work if the user is logged in. In my local dev env, also if the user is not logged in. But on the live server it does not work when the user is not logged in.

Funny thing is, even if the redirect works (logged in user), the drupal log show a page not found entry for that url. So it seems that even with the eventsubscriber solution, drupal handels the 404 part first, and then executes my code.

Any ideas what I'm doing wrong? Or suggestions how to manage what I'm trying to do?

Source Link
Loading