0

This code below for rewrite/redirect from localhost/moneyworld/exchange?title=BTC_PMUSD to localhost/moneyworld/BTC_PMUSD but i want to rewrite/redirect from www.domain.com/exchange?title=BTC_PMUSD to www.domain.com/BTC_PMUSD Without also /moneyworld/

RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/(moneyworld)/exchange\?title=([^\s]*)\s [NC]
RewriteRule ^ /%1/%2 [NE,QSD,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ /moneyworld/exchange?title=$2 [L]  

Thanks

  • Does this answer your question? [.htaccess rewrite to redirect root URL to subdirectory](https://stackoverflow.com/questions/990392/htaccess-rewrite-to-redirect-root-url-to-subdirectory) – Umair Mubeen Jan 12 '21 at 10:24
  • Is it to all the requests you want to add `www` or only this specific request? Please confirm once. Is there any error you are getting for your current rules? – RavinderSingh13 Jan 12 '21 at 10:24
  • Yes also i want to add www – Mohamed Nabil Jan 12 '21 at 10:25
  • @MohamedNabil The other question, that you just deleted - you need to delegate the event. This is a good time to learn about event delegation. – Mitya Jan 14 '21 at 11:19
  • @Mitya how to delegate it ? i don't understand! – Mohamed Nabil Jan 15 '21 at 10:10
  • @MohamedNabil Did you read a tutorial on event delegation or research it? You can read [my guide here](https://mitya.uk/articles/javascript-event-delegation#event-delegation-less-code). The concept is to bind the event to a common parent, not to the element directly. This means it works for "live" (i.e. future) elements, not just those present on page load. – Mitya Jan 15 '21 at 10:53

1 Answers1

0

The problem was that i was forwarding exchange.php to exchange after the url rewrite rules so simply the code below solved it

RewriteEngine ON
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{THE_REQUEST} \s/exchange\?title=([^\s]*)\s [NC]
RewriteRule ^ /%1 [NE,QSD,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /exchange?title=$1 [L]