This topic contains a post which is marked as Best Answer. Press here if you would like to see it.
*

Ajit Sahane

  • ****
  • 147 posts
  • https://bestclassifiedsusa.com
I want htaccess code for 301 redirection

old ad format -  xyz.com/for-sale/bike-for-sale_i123    but i am changed  underscore to hyphen format

now new ad format -  xyz.com/for-sale/bike-for-sale-i123   

In this case, my site all ads want 301 redirection & manual 5000+ ads not possible for each ad htaccess code

So, want dynamic htaccess 301 code for only work in i_    to i-   case   

I am trying but then all other pages wrongly redirected.

Any expert solution ....?

Must IMP forgotten point in Osclass.



« Last Edit: December 04, 2020, 07:26:19 AM by MB Themes »

*

MB Themes

Re: Ad redirect _ to - via htaccess
« Reply #1 on: December 03, 2020, 08:28:59 PM »
I was doing that recently and simply autogenerated code using loop and put there to htaccess.
You need to do it just temporary for month or so.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Ajit Sahane

  • ****
  • 147 posts
  • https://bestclassifiedsusa.com
Re: Ad redirect _ to - via htaccess
« Reply #2 on: December 04, 2020, 03:23:02 AM »
Can you share htaccess code here ...?

I am using Redirect 301 /xyz.com/for-sale/bike-for-sale_i123 https://www.xyz.com/for-sale/bike-for-sale-i123

but each ad not possible. huge list

any loop code? so all ad auto work as per the new format.
« Last Edit: December 04, 2020, 03:27:02 AM by Ajit Sahane »

Marked as best answer by frosticek on December 04, 2020, 01:14:35 PM
*

MB Themes

Re: Ad redirect _ to - via htaccess
« Reply #3 on: December 04, 2020, 07:25:30 AM »
@Ajit
Try this one.

Code: [Select]
    $mSearch = new Search() ;
    $mSearch->limit(0, 9999) ;
    $aItems = $mSearch->doSearch();
    View::newInstance()->_exportVariableToView('items', $aItems);

    if(osc_count_items() > 0) {
      while(osc_has_items()) {
        echo 'Redirect 301 ' . str_replace(osc_base_url(), '/', osc_item_url()) . ' ' . str_replace('_', '-', osc_item_url()) . '<br/>';
      }
    }

You generate this code before you change"_" into "-", save output to htaccess and immediatelly change permalink settings.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Ajit Sahane

  • ****
  • 147 posts
  • https://bestclassifiedsusa.com
actually i am alreday changed permalink

and now some ad recrwal 404 bucz _     

How to do now ...?


if any old ad link found i_   then when click want auto redirect to i-                 like this  via htaccess

So, its help all old ads auto redirect and 404  gone   or recrwal 200- ok found.

While permalink setting i-    ON  case   how to do ...? Pls share working code.
« Last Edit: December 04, 2020, 11:56:46 AM by Ajit Sahane »

*

MB Themes

Already shared working code.
You can customize it by your needs and preferences.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Ajit Sahane

  • ****
  • 147 posts
  • https://bestclassifiedsusa.com
So, shared code where to add in function.php or htaccess ...?


*

MB Themes

@Ajit
PHP code probably belongs to .php file.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Ajit Sahane

  • ****
  • 147 posts
  • https://bestclassifiedsusa.com
Code not clear -  error code

*

MB Themes

Code is correct, works ok for me.
I think you will need at least basic knowledge of PHP to be able to work with such code successfully.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots