0

I'm using osclass and in the search url it's return commas in the url example :

http://127.0.0.1/search/keyword,trt
http://127.0.0.1/search/keyword,trt/category,photography

I want to change the urls somthing like :

http://127.0.0.1/search/keyword-trt
http://127.0.0.1/search/keyword-trt/category-photography

My .htaccess now is

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

#I add this line but not working
RewriteRule ^(.*),(.*)$ /$1-$2 [L,R=301]
</IfModule>

I deactive friendly SEO URL but still htaccess not working

Bynd
  • 675
  • 1
  • 15
  • 40
  • In HTML source of your web pages do you see URLs like this `/search/keyword,trt/category,photography`? If yes, then you need to change settings in `osclass`. htaccess rules cannot change generated HTML. – anubhava Sep 24 '22 at 05:16
  • @anubhava when I do search in search bar trt I hit enter I get a url result `http://127.0.0.1/search/keyword,trt` I want to change that to return `http://127.0.0.1/search/keyword-trt` – Bynd Sep 24 '22 at 05:19
  • Hitting search button usually results in a form submission. Form handler would be some backend php code. Can you just do `str_replace` in your php code? – anubhava Sep 24 '22 at 05:24
  • 1
    Check this: https://github.com/osclass/Osclass/issues/974 on how to do this. – anubhava Sep 24 '22 at 05:26
  • @anubhava I already saw that page there is no solution there are talking about seo but none of theme give a solution – Bynd Sep 24 '22 at 05:34
  • See .htaccess rules can rewrite/redirect an incoming request but here is something happening in the backend that runs after .htaccess so you need to handle it on backend/javascript only. – anubhava Sep 24 '22 at 06:10
  • I looked everywhere I couldn't find anywhere where to change that I don't find any js file handle this – Bynd Sep 24 '22 at 06:32
  • @anubhava I deactive frendly SEO URL but still htaccess not working – Bynd Sep 24 '22 at 07:04
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/248311/discussion-between-bynd-and-anubhava). – Bynd Sep 24 '22 at 07:11
  • after deactivating SEO what URL are you getting (test in a new browser)? – anubhava Sep 24 '22 at 07:31
  • If the result of your search form submission results in commas in the URL then you need to resolve this in your PHP/JS code, not `.htaccess`. Even if you were to implement a redirect in `.htaccess` to change the `,` to `-` then your PHP/JS may not interpret the request correctly, since it would seem to be expecting `,`, not `-`. – MrWhite Sep 24 '22 at 10:43
  • `#I add this line but not working` - of course not, because it never gets that far - the RewriteRule above that, in combination with the RewriteConds, has already rewritten any request that does not map onto an existing file or folder, to the index.php, and said that was the [L]ast rule to process in this round. You need to get the order right first of all. – CBroe Sep 26 '22 at 06:56
  • @CBroe sorry I don't understand `You need to get the order right first of all` – Bynd Sep 28 '22 at 01:29
  • You need to do this before the general rewrite of everything non-existing to the index.php. – CBroe Sep 28 '22 at 05:58

0 Answers0