How to URL rewrite with my case - php

I know that this site has many questions about URL rewriting. But as a newbie, I could not find the correct answer for my case.
My question is: I would like to rewrite the original URL like this: when user visit:
http://username.example.com/a/b/c/d/e/f/g/h...
the apache will process request as
http://example.com/index.php?user=username&a=b&c=d&e=f&g=h...
According to what I knew, the solution could be using QUERY STRING, but I don't know how to do that.
Any help will be appreciated! Thanks,

The first thing you need for this is to create Dynamic sub-domain. create dynamic subdomain link will help you in this. Use following config for your case:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule (.*) http://example.com/$1 [R=301,L]
RewriteRule ^([aA-zZ])$ index.php?user=$1
RewriteCond %{HTTP_HOST} ^(^.*)\.example.com
RewriteRule (.*) index.php?user=%1
once this is in place, you can add more conditions for the remaining parameters.

Related

.htaccess - rewrite one uri, but all redirected to HTTPS

I am really struggling to get .htaccess correct. I basically want to convert
product.php?sku=M1234 for example to display as M1234.php and to be able to type ../M1234.php to take to perform that operation. I also want all pages on the website to be HTTPS.
I have tried this:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,N]
RewriteRule ^([^/]*)\.html$ /products/product.php?product_id=$1 [L]
With no success. Any advice would be most appreciated.
Many thanks
Use:
RewriteRule ^([A-Za-z0-9-]+)/?$ /products/product.php?sku=$1 [NC,L] # Handle product requests
This will use website.com/test to request website.com/products/product.php?sku=test

Redirecting multiple URLS with parameters via htaccess

I've seen plenty of answers here about this question but none seem to help me.
I have a list of about 300 URLs that all have parameters in them. I want to redirect each one to different URLs on a new domain. The thing is, the redirection is determined by the content of the page, not param name = page name or something of the sort.
So, I have a list of old page = new page, how would I create something like that in htaccess?
If there were no parameters I would do:
Redirect 301 /old-page-name/ http://newurl.com/new-page-name
however that doesn't work.
Any ideas?
Edit:
I tried this and it doesn't work. Possibly this would be easier for anyone to help out with?
RewriteCond %{HTTP_HOST} muflaim\.co\.il [NC]
RewriteCond %{REQUEST_URI} ^/shop/classic?page=shop.product_details&category_id=&flypage=flypage_experience.tpl&product_id=200$
RewriteRule ^(.*)$ http://www.dreambox.co.il/45217/ [R=301,L,NC]
Just in case anyone finds this helpful, this did the trick:
RewriteEngine on
RewriteCond %{HTTP_HOST} muflaim\.co\.il [NC]
RewriteCond %{QUERY_STRING} ^page=shop.product_details&category_id=&flypage=flypage_experience.tpl&product_id=200$ [NC]
Rewriterule ^shop/classic$ http://www.dreambox.co.il/45217? [R=301,L,NC]

http to https redirect htaccess not working

I found a lot of similar answers but so far I could not manage the right thing that I want. It seems very easy or maybe somebody already answered but for me it's not working anymore..
So at the end I want https://example.com/product/624567
In my htaccess file I have already a rule something like this
RewriteEngine On
RewriteRule ^([a-z0-9-]{1,40})/([0-9]{1,12})$ fixMe.php?request=$2 [L]
Now if someone calls a URL following the above mentioned pattern with or without https all time it should redirect to the desired url(https://example.com/product/624567). To achieve this redirect I set another rule something like
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} product
RewriteRule ^product/([0-9]{1,12})$ https://%{HTTP_HOST}/product/$1 [L,R=301,NE]
But I am always getting a 404 error!! Could anyone please help me what i am doing wrong. Thanks
Try with:
RewriteCond %{HTTPS} off
RewriteRule ^product/[0-9]{1,12}$ https://%{HTTP_HOST}%{REQUEST_URI} [NC,NE,L,R=301]
But just place the lines after RewriteEngine On and before RewriteRule ^([a-z0-....;

URL rewriting with PHP variable

So I know the basics of URL rewriting, but there was something more complex that I couldn't get done or know if it can be done.
From:
http://www.example.com/file.php?name=Sam&id=23
To:
http://www.example.com/Sam/file/23
I basically want to know if this is possible and if it is, how it can be accomplished?
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /$2.php?name=$1&id=$3 [L]
Use the below htaccess redirection rule.
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/(.*)/(.*)/([0-9]+)$
RewriteRule ^(.*)/(.*)/(.*)$ /$2.php?name=$1&id=$3 [L]
To get the vales use in php
$_GET['name'];//Sam
$_GET['id'];//23

mod_rewrite {QUERY_STRING}

I'm sure that's been asked zillions times but i can't get it to work,
i'm trying to rewrite a url with querystring, my url is for example:
http://example.com/articles/index.php?keyword=book
and i want to be accessible from
http://example.com/articles/keyword/book/
I google it and i didn't have any luck,
am i on the right track? i got this:
RewriteCond %{QUERY_STRING} ^keyword=(.*)$ [NC]
RewriteRule ^/articles/index.php$ /articles/keyword/$1 [NC,L,R=301]
UPDATE
this is working fine
RewriteEngine On
Options +FollowSymLinks
RewriteBase /
RewriteRule ^.*/(\w+)\b$ /articles/index.php?keyword=$1
It should work:
RewriteRule ^articles/keyword/(.*)/?$ index.php?keyword=$1
If not, please tell me ;)

Categories