2

I have website. I just want to rewrite url using .htaccess Here is the code which I want to rewrite:

RewriteEngine On RewriteBase / RewriteCond %{QUERY_STRING} /search_data.php\?keywords=([^&]+)&f=([^\s&]+) [NC] RewriteRule ^/search_data.php/?$ /search/%1/%2? [R=301,L,NC] 

this the current url

http://localhost/mywbsite/search_data.php?keywords=one+piece&f=149 

I want to convert this to this

http://localhost/mywbsite/search/one-piece/149 

I tried above code but its not working please help me

1 Answer 1

2

QUERY_STRING is only used to match query string without URI.

You need to use:

Options -MultiViews RewriteEngine On RewriteBase /mywbsite/ RewriteCond %{THE_REQUEST} /search_data\.php\?keywords=([^&]+)&f=([^\s&]+) [NC] RewriteRule ^ search/%1/%2? [R=301,L] RewriteRule ^search/([^/]+)/([^/]+)/?$ search_data.php?keywords=$1&f=$2 [QSA,L,NC] 
Sign up to request clarification or add additional context in comments.

10 Comments

hey hi its work but problem is its removing my folder name also from url also after this code my url is localhost/search/one+piece/149
i mean after your htaccess code my new url is localhost/search/one+piece/149 and and i want url like this localhost/mywbsite/search/one-piece/149 above code removing mywbsite i.e. my project name
thax it work for me i can't give you 1 up i don't have enough reputation sory
No issues, accepting the answer is more than enough. Though you have 15+ reps now :)
hey hi after this code page is properly redirect but the problem is css, js and image loading like this localhost/search/one+piece/149/styles/metro_blue/theme/large.css
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.