Osclass Support Forums

Osclass theme support => Ideas, improvements and tips => Topic started by: Ajit Sahane on December 03, 2020, 05:06:55 PM

Title: Change item URL character "_" into "-" and redirect old listings via .htaccess
Post by: Ajit Sahane on December 03, 2020, 05:06:55 PM
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.



Title: Re: Ad redirect _ to - via htaccess
Post by: MB Themes 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.
Title: Re: Ad redirect _ to - via htaccess
Post by: Ajit Sahane 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.
Title: Re: Ad redirect _ to - via htaccess
Post by: MB Themes 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.
Title: Re: Change item URL character "_" into "-" and redirect old listings via .htaccess
Post by: Ajit Sahane on December 04, 2020, 11:50:10 AM
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.
Title: Re: Change item URL character "_" into "-" and redirect old listings via .htaccess
Post by: MB Themes on December 04, 2020, 12:15:48 PM
Already shared working code.
You can customize it by your needs and preferences.
Title: Re: Change item URL character "_" into "-" and redirect old listings via .htaccess
Post by: Ajit Sahane on December 04, 2020, 12:33:36 PM
So, shared code where to add in function.php or htaccess ...?

Title: Re: Change item URL character "_" into "-" and redirect old listings via .htaccess
Post by: MB Themes on December 04, 2020, 01:14:28 PM
@Ajit
PHP code probably belongs to .php file.
Title: Re: Change item URL character "_" into "-" and redirect old listings via .htaccess
Post by: Ajit Sahane on December 04, 2020, 01:21:14 PM
Code not clear -  error code
Title: Re: Change item URL character "_" into "-" and redirect old listings via .htaccess
Post by: MB Themes on December 04, 2020, 02:16:56 PM
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.