How do i URL rewrite using .htacess - .htaccess

i need some help rewriting URL using .htaccess my urls looks like:
http://www.example.com/testro2/product.php?id=426834&productStore=396
And i need have it work with text into it, example:
http://www.example.com/testro2/product/{anythinghere}/id=4268334&productStore=369
or you can make it look more clear like removing id= and &productStore= will be great, else i can use with them. example
http://www.example.com/testro2/product/{anythinghere}/4268334/396
The thing is that i need to have my keyword anythinghere in the URL.
Also, i would like to rewrite
http://www.example.com/testro2/search.php?q=shoes
TO
http://www.example.com/testro2/search/shoes

You can put this code in your /testro2/.htaccess
RewriteEngine On
RewriteBase /testro2/
RewriteRule ^product/.+/(\d+)/(\d+)$ product.php?id=$1&productStore=$2 [L]
RewriteRule ^search/(.+)$ search.php?q=$1 [L]

Related

How to add a rewrite rule to remove paramaters in htaccess? [duplicate]

I Want to rewrite the url using .htaccess
Plz Read the code, and you well Get to know What I mean
My URL :
article.php?id=1&title=example
Using this in .htaccess
RewriteRule ^article/([0-9]+)/([0-9a-zA-Z_-]+)$
article.php?id=$1&title=$2 [NC,L]
I get
article/1/example
What i need is
article/example
So something like this:
RewriteRule ^article/([0-9a-zA-Z_-]+)$ article.php?title=$1 [NC,L]

htaccess to remove part of a url, .htaccess

I was wondering how it is possible to remove part of a url with htaccess for example I have a url like this:
http://localhost/item.php?pa=gd34392
now I need to use htaccess to redirect this page or anything like this to a page with this url:
http://localhost/gd34392
I have tried things like this but nothing seems to work and I do not really know my way around htaccess
RewriteEngine on
RewriteRule item.php?pa=$1 /$1 [R=301,L]
You can achieve that using the following rules in your .htaccess:
RewriteEngine On
RewriteRule ^([^/]*)$ /item.php?pa=$1 [L]
Just make sure you clear your cache before testing this.

.htacess url rewrite rule to shortern the url and remove "?st_id=" from it

I currently goto:
support-requests/?st_id=7
Ideally i would like to just go straight here using .htaccess url-rewriting to make the page neater to look at and navigate to without the "?st_id=" being displayed in the url.
support-requests/7
This is what i currently have but i know its wrong and it does not work:
RewriteCond %{QUERY_STRING} ^(\w+)=(\w+)$
RewriteRule support-requests/ support-requests/%1/%2/?
Could i have some assistance in getting this correct please?
Thanks
Use this:
RewriteEngine On
RewriteRule ^support-requests/([^/]*)$ /support-requests/?st_id=$1 [L]
Should leave you with:
www.example.com/support-requests/7

htaccess rewrite URL from subdirectory

I've been trying to set up a rewrite rule in our htaccess. We have a search component that directs to the URL:
http://www.domain.co.uk/component/search?searchword=word&searchphrase=all&start=10
We'd like to show it as:
http://www.domain.co.uk/search/word/10
I've been trying this with no avail so far, this is what I have.
RewriteEngine On
RewriteRule ^search/([^/]*)/([^/]*)$ /component/search/?searchword=$1&searchphrase=all&start=$2 [L]
Is there something missing? Could other rules be interfering with it?
At least you should escape the slashes and the question mark
RewriteRule ^search/([^/]*)/([^/]*)$ /component\/search\/\?searchword=$1\&searchphrase=all\&start=$2$ [L]
And you should not put ampersands (&) in your query string - use %26 or & instead...
You generate your link in the first place as
http://www.domain.co.uk/search/word/10
and use .htaccess such as
RewriteEngine On
RewriteRule ^search/([^/]+)/([^/]+)/? /component/search/search.php?searchword=$1&searchphrase=all&start=$2 [L]
to rewrite it to the dynamic form your search.php script can handle. Your attempt basically looks OK (except that you need search.php, not search), so you might want to check if "mod rewrite" is enabled on your server. You might have to wrap the above code in
<IfModule "mod_rewrite.c">
RewriteEngine...
</IfModule>
Consult with your hosting service.

rerwrite url in .htaccess

I want to make the old urls point to the new pages. I'm having trouble because the old URL looks like this: http://nilandsplace.com/store/camping_eng/coghlans-campfire-cooking-forks-toaster-forks-package-of-4.html.
I want to do a URL re-right in .ht access from mywebsite.com/camping_eng/some.html to mywebsite.com/camping/some.html, were the "some.html" part is identical.
Only camping_eng changes to camping.
You might want to try this:
RewriteEngine on
RewriteRule ^camping_eng/([a-zA-Z0-9-=_.]+)/?$ http://mywebsite.com/camping/$1 [L,R=301]
This example works according to your question:
from mywebsite.com/camping_eng/some.html
to mywebsite.com/camping/some.html were the "some.html" part is identical.
RewriteEngine on
RewriteBase /store
RewriteRule ^camping_eng/(.*)$ camping/$1 [QSA,L,R=301]

Resources