Mohamed Nabil
Mohamed Nabil

Reputation: 39

How to redirect a URL and then rewrite it to same url with htaccess?

There is PHP file redirect to

header("location:./exchange?title=".$directionin. '_'. $directionto);

I want to re-write this URL localhost/moneyworld/exchange?title=BTC_PMUSD to this localhost/moneyworld/BTC_PMUSD i have tried

RewriteEngine On
RewriteRule ^([^/]*)\.html$ /moneyworld/exchange?title=$1 [L]

and i put the .htaccess file in the root and it didn't work then i put it in moneyworld folder and also it didn't work.

Upvotes: 1

Views: 147

Answers (1)

RavinderSingh13
RavinderSingh13

Reputation: 133528

Could you please try following(based on your shown samples), In case you are looking to rewrite/redirect from localhost/moneyworld/exchange?title=BTC_PMUSD to localhost/moneyworld/BTC_PMUSD URL then try following

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]  

Upvotes: 2

Related Questions