Multiple variables in rewrite mod - .htaccess

I am new in rewrite mod and i want to make something like when user go to: http: mysite.qqq/news/it/some_news1 real URL will be: http:// mysite.qqq/index.php?s=news&d=it&i=some_news1. But i don't know how to make this. I need help.
Now i have .htaccess:
RewriteEngine On
RewriteRule ^([a-z_]*)/?$ index.php?s=$1 [QSA]
And i am thinking to add something like:
RewriteRule ^([a-z_]*)/([a-z_]*)/([a-z0-9_]*)/?$ index.php?s=$1&d=$2&i=$3 [QSA]
But it doesn't working.

RewriteRule ^/(.+?)/(.+?)/(.+?) mysite.qqq/index.php?s=$1&d=$2&i=$3 [QSA]

Related

URL rewrite for a clean format

i am trying to have my urls look like cleaner using the below but its not working i don't know if i should add anything else,
this is how it looks now
example.com/product.php?product_id=144&product_name=50ml-bottle-with-glasses,-shirt
this is how i want them to look
example.com/product/144/50ml-bottle-with-glasses,-shirt
basically here's what i used
RewriteEngine On
RewriteRule ^product/([0-9]+)/([A-Za-z0-9-]+)/?$ product.php?product_id=$1&product_name=$2 [NC,L] # Handle product requests
Thank you
This should work :
RewriteEngine On
#1)redirect from "/product\.php\?product_id=123&product_name=foo" to "/product/123/foo"
RewriteCond %{THE_REQUEST} /product\.php\?product_id=([^&]+)&product_name=([^\s&]+) [NC]
RewriteRule ^ /product/%1/%2? [NE,L,R]
#2)internally map "/product/123/foo" to "/product\.php\?product_id=123&product_name=foo"
RewriteRule ^product/([0-9]+)/(.+)/?$ product.php?product_id=$1&product_name=$2 [B,NC,L]
There are comma into your parameter product_name. Try to change your .htaccess and add comma into your regular expression for this parameter: ([A-Za-z0-9-,]+). So your htaccess will be something like this:
RewriteEngine On
RewriteRule ^product/([0-9]+)/([A-Za-z0-9-,]+)$ product.php?product_id=$1&product_name=$2 [NC,L] # Handle product requests

Using .Htaccess url redirection

I want to rewrite my url but i cant do proper way.
mysitename.net/index.php?title=Category:Public_Companies&pagefrom=8
To :
mysitename.net/Category:Public_Companies/8
How can i do that.
If you have other pages than Category, I recommend to use this:
RewriteRule ^Category:(.+)/(.+)$ /index.php?title=Category:$1&pagefrom=$2 [L]
Otherwise, use this:
RewriteRule ^(.+)/(.+)$ /index.php?title=$1&pagefrom=$2 [L]

htaccess mod rewrite $_GET to variables with slashes

I would like to rewrite URL's with htaccess to better readable URL's and use the $_GET variable in PHP
I sometimes make use of a subdomain so it has to work with and without. Also are the variables not necessary in the url. I take a maximum of 3 variables in the URL
the URL sub.mydomain.com/page/a/1/b/2/c/3 should lead to sub.mydomain.com/page.php?a=1&b=2&c=3 and the url sub.mydomain.com/a/1/b/2/c/3 should lead to sub.mydomain.com/index.php?a=1&b=2&c=3 where $_GET['a'] = 1
I came up with this after searching and trying a lot
RewriteEngine on
RewriteRule ([^/]+)\.domain.com/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ $1.domain.com/$2.php?$3=$4&$5=$6&$7=$8 [QSA,NC]
RewriteRule ([^/]+)\.domain.com/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ $1.domain.com/index.php?$2=$3&$4=$5&$6=$7 [QSA,NC]
RewriteRule ([^/]+)\.domain.com/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ $1.domain.com/$2.php?$3=$4&$5=$6 [QSA,NC]
RewriteRule ([^/]+)\.domain.com/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ $1.domain.com/index.php?$2=$3&$4=$5 [QSA,NC]
RewriteRule ([^/]+)\.domain.com/([^/]+)/([^/]+)/([^/]+)$ $1.domain.com/$2.php?$3=$4 [QSA,NC]
RewriteRule ([^/]+)\.domain.com/([^/]+)/([^/]+)$ $1.domain.com/index.php?$2=$3 [QSA,NC]
RewriteRule ([^/]+)\.domain.com/([^/]+)$ $1.domain.com/$2.php [L,QSA,NC]
but what I get is an not found server error
I'm not that good at this so maybe I oversee something.
Also I would like it to work with and without a slash at the end
Should I make use of RewriteCond and/or set some options?
Thanks in advance.
When using RewriteRule, you don't include the domain name in the line. Also, make sure you turn on the RewriteEngine first. Like this:
RewriteEngine On
RewriteRule ^([^/]+)/([^/]+)$ index.php?$1=$2
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)$ index.php?$1=$2&$3=$4
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$ index.php?$1=$2&$3=$4&$5=$6
The first line will rewrite sub.mydomain.com/a/1 to sub.mydomain.com/page.php?a=1, the second rewrites sub.mydomain.com/a/1/b/2 to sub.mydomain.com/page.php?a=1&b=2, and so on.

.htaccess Rewrite /... to /?url=

I am trying to rewrite URLs like this: http://url.maxk.me/abc to http://url.maxk.me/?url=abc, but for some reason it is not working.
Please can you tell me what I am doing wrong?
RewriteEngine on
RewriteRule ^(?:.*)url.maxk\.me/(.*)/?$ url.maxk.me?url=$1
You shouldn't include the domain in the RewriteRule target resource.
It should look like the following if you want the "?url" part to be visible to the user:
RewriteRule ^(.*)$ http://url.maxk.me/?url=$1
Otherwise, if you don't want the user to see "?url", it should look like this:
RewriteRule ^(.*)$ ?url=$1
try using this:
RewriteRule ^(.*)$ ?url=$1

htaccess : rewrite urls

please help to rewrite Urls from
http://www.site.com/index.php?cat=catname
and
http://www.site.com/index.php?id=productname
to be like this
http://www.site.com/catname
and
http://www.site.com/productname
i think it will require php check if the page is cat work with it as cat
or its product work with it as product
in .htaccess file:
RewriteEngine On
RewriteRule ^([0-9a-z\-\_]+)?$ /index.php?id=$1 [L,QSA,NC]
category/product check must be done in index.php...
Or you can add extra slug
RewriteRule ^(category)/([0-9a-z\-\_]+)?$ /index.php?category=$1 [L,QSA,NC]
RewriteRule ^(product)/([0-9a-z\-\_]+)?$ /index.php?product=$1 [L,QSA,NC]
but url will look like http://site.com/category/catname
http://www.site.com/catname and http://www.site.com/productname
The problem with that scheme is that you can't tell whether it's a catalog name or a product name by the URL. As a result, you'll probably want something like this:
http://www.site.com/Catalog/catname and http://www.site.com/Product/productname
Which can then be implemented in a .htaccess file with the following rules:
RewriteEngine On
RewriteRule ^Catalog/(.+)$ /index.php?cat=$1 [L]
RewriteRule ^Product/(.+)$ /index.php?id=$1 [L]

Resources