-1

I would appreciate if someone could help me. I’m getting so confused.

I want to redirect

https://xklsv.me/viewblog.php?title=working-plans-survey-and-demarcation-of-the-karnataka-forest-department/aranya_kfd/November-8th-2018

To:

https://xklsv.me/working-plans-survey-and-demarcation-of-the-karnataka-forest-department/aranya_kfd/November-8th-2018

but 301 moved permanantly not working giving 200 ok status code

1 Answers1

0

Well, this sounds pretty straight forward, exactly as the documentation shows in examples:

RewriteEngine on

RewriteCond %{QUERY_STRING} ^title=working-plans-survey-and-demarcation-of-the-karnataka-forest-department/aranya_kfd/November-8th-2018$
RewriteRule ^/?viewblog\.php$ /working-plans-survey-and-demarcation-of-the-karnataka-forest-department/aranya_kfd/November-8th-2018 [R=301,QSD]

RewriteRule ^/?working-plans-survey-and-demarcation-of-the-karnataka-forest-department/aranya_kfd/November-8th-2018/?$ /viewblog.php?title=working-plans-survey-and-demarcation-of-the-karnataka-forest-department/aranya_kfd/November-8th-2018 [END]

If that should be implemented in a more general way that should work:

RewriteEngine on

RewriteCond %{QUERY_STRING} ^title=([^&]+)$
RewriteRule ^/?viewblog\.php$ /%1 [R=301,QSD]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([^/]+)/?$ /viewblog.php?title=$1 [END,QSA]

You may need to tweak this a little, but it should point you into the right direction...

It is a good idea to start out with a 302 temporary redirection and only change that to a 301 permanent redirection later, once you are certain everything is correctly set up. That prevents caching issues while trying things out...

In case you receive an internal server error (http status 500) using the rule above then chances are that you operate a very old version of the apache http server. You will see a definite hint to an unsupported [END] flag in your http servers error log file in that case. You can either try to upgrade or use the older [L] flag, it probably will work the same in this situation, though that depends a bit on your setup.

This implementation will work likewise in the http servers host configuration or inside a dynamic configuration file (".htaccess" file). Obviously the rewriting module needs to be loaded inside the http server and enabled in the http host. In case you use a dynamic configuration file you need to take care that it's interpretation is enabled at all in the host configuration and that it is located in the host's DOCUMENT_ROOT folder.

And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using dynamic configuration files (".htaccess"). Those dynamic configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server. They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare).

arkascha
  • 41,620
  • 7
  • 58
  • 90
  • thanks for your answer but google search still giving old url please check with this keyword "aranya_kfd xklsv.me" – Prakash yadav Nov 19 '19 at 16:24
  • The google index is not a live updated catalog. It takes days if not weeks until results are updated. And older, outdated hits may not get removed for month. – arkascha Nov 19 '19 at 16:43
  • in this case website accessing from both url. is it generating two url. – Prakash yadav Nov 20 '19 at 06:04
  • Of course there are two URLs. There is nothing you can do against it. One of them (`/viewblog.php?title=...$`) get's redirected. If that is not the case _for you_ then you are most likely looking at a cached result due to the fact that you started out using a 301 redirection, so a permanent redirection which will get cached. Try using an anonymous browser window or better even test with another system or browser. – arkascha Nov 20 '19 at 08:46
  • @arkasha 301 permanant redirection is not working i have checked it with another system also /viewblog.php?title is still coming – Prakash yadav Nov 20 '19 at 10:48
  • I made an explicit check using one of my systems and confirmed that the first rule set works as expected. If it does _not_ work for you then there must be some other issue coming into play here which you did not mention in the question. Please post the _exact_ URL you are testing with. – arkascha Nov 20 '19 at 11:06
  • just fourth article of the website https://xklsv.me/viewblog.php?title=philanthropy/fred//November-13th-2019 – Prakash yadav Nov 20 '19 at 11:08
  • That URL is a different one from what you posted in the question. So I understand that you are actually looking for a general approach? And that you are using the second variant in the question? – arkascha Nov 20 '19 at 11:10
  • yes actually it is dynamically url just viewblog.php?title=anydynamic text please visit the website and check the url – Prakash yadav Nov 20 '19 at 11:13
  • As said: the rules work fine, so the issue has to be something else. Are you really certainly that those rules are executed _at all_ ? How did you check? Are there any other rules that might come into play? _How did you check_ ? What does your http server's error log file reveal? – arkascha Nov 20 '19 at 11:20
  • RewriteEngine on RewriteEngine was now turned on 2 RewriteCond %{QUERY_STRING} ^title=([^&]+)$ This condition was met. 3 RewriteRule ^/?viewblog\.php$ /%1 [R=301,QSD] The new url is https://xklsv.me/shadowstalker/fred//November-14th-2019 Test are stopped, a redirect will be made with status code 301 4 RewriteCond %{REQUEST_FILENAME} !-f This rule was not met. 5 RewriteCond %{REQUEST_FILENAME} !-d This rule was not met. 6 RewriteRule ^/?([^&]+)/?$ /viewblog.php?title=$1 [END,QSA] This rule was not met. – Prakash yadav Nov 20 '19 at 11:28
  • rules working fine then what could be the issue. why it is not reflecting – Prakash yadav Nov 20 '19 at 11:31
  • You should always test with a 302 redirection to prevent caching issues, I mentioned that in my answer... But there is another thing that strikes odd: if the rewriting tests are stopped, then how come additional tests are performed? Even if they do not match? That makes no sense. I assume the redirection _does_ work, your browser does send a second request, but that one fails. Please use your browsers development console to check each step. Again, start with a cleared cache. – arkascha Nov 20 '19 at 11:36
  • it is giving 200 status code – Prakash yadav Nov 20 '19 at 12:00
  • Both statements you made contradict each other. Something is fishy here. – arkascha Nov 20 '19 at 12:09
  • is there any way to make it work i have checked everything properly but didn't get how to resolve that. – Prakash yadav Nov 21 '19 at 10:17
  • I can't say anything in addition to what I said... If your http server logs that it sends out a 301 redirection and your browser does not receive such, then something is off. Either you did not look at the right places, not at current data, or you have some other instance getting into the way, a proxy for example or a firewall application caching results. – arkascha Nov 21 '19 at 11:27