mod_rewrite clean urls with alphabets - .htaccess

I was using mod rewrite to create clean urls. I have urls like this :
http://www.sitename.com/viewcategory.php?id=262
I have rewritten successfully my url like this :
http://www.sitename.com/262
With the following mod_rewrite rule
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)$ viewcategory.php?id=$1
RewriteRule ^([a-zA-Z0-9]+)/$ viewcategory.php?id=$1
What i want is to display the category name somthing like this:
http://www.sitename.com/categoryname
Please suggest me if there is a mistake in my rewrite rule or I need to do something else.
Thanks and regards.

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.

How do i URL rewrite using .htacess

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]

Htaccess rewrite clean categories & articles

I have a URL that looks like this:
example.com/index.php?p=blog&category=blog&article=blog-test
But I'd like to have it look like:
example.com/blog/blog/blog-test
How would I be able to do this with htaccess?
You can use .htaccess:
RewriteEngine on
RewriteRule ^(.+?)/(.+?)/(.+)$ index.php?p=$1&category=$2&article=$3 [L]

.htaccess rewrite rule is discarding my querystring

My URL is like
http://172.16.3.97:82/shop/t-shirts/full-zip-sweatshirt?options=367:731,368:737,369:741&custom_inscription=test
and I wrote rewrite rule like
RewriteRule ^shop/t-shirts/([a-zA-Z0-9\-#]+)\?*$ shop/product?path=35&product_id=$1&test=$2
I got only full-zip-sweatshirt in $_GET but I am not able to get other parameters.
How should I write Rule in .htaccess ?
Try to change your rewrite rule for this :
RewriteRule ^shop/t-shirts/([a-zA-Z0-9-#]+)\?*$ shop/product?path=35&product_id=$1&test=$2 **[L,QSA]**
The flag "QSA" add the original query string to your query
Or maybe this one should also help :
RewriteRule ^shop/t-shirts/([a-zA-Z0-9-#]+)\?*$ shop/product?path=35&product_id=$1&test=$2&%{QUERY_STRING}

Resources