Osclass Support Forums
Osclass theme support => Ideas, improvements and tips => Topic started 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.
-
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.
-
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.
-
@Ajit
Try this one.
$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.
-
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.
-
Already shared working code.
You can customize it by your needs and preferences.
-
So, shared code where to add in function.php or htaccess ...?
-
@Ajit
PHP code probably belongs to .php file.
-
Code not clear - error code
-
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.