How to change change URL format to POST using htacess php? - php

I have htaccess tha handle redirections know i want to hit api like i have a url like that
http://localhost:8080/test/network/country/category/subcategory/fixedvalue
I have fixed value like detail, category ,codes but only in case of detail i need id as parameter
example
http://localhost:8080/test/Airtel/UK/Prepaid/5G/Detail
below is redirect url that i want to generate from htacess file
if fixed value is detail
http://localhost:8080/h1.php?network=Airtel&country=UK&category=Prepaid&subcategory=5G&Detail=remain portion of url except .html
in other cases where detail is not in fixed i don't need id that have parameter the remaining portion of url after 5th parameter so url will be
http://localhost:8080/h1.php?network=Airtel&country=UK&category=Prepaid&subcategory=5G
here is a code that redirect to 5.php file so that but i want not redirection i want a specific url having parameter
RewriteEngine On
RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/([\w-]+)/([\w-]+)/?$ 5.php?1=$1&2=$2&3=$3&4=$4&5=$5 [QSA,L]
in simple from
www.cloth.com/nike to www.cloth.com?name=nike

Related

url rewrite rules in htaccess with php mysql

How write url rewrite rules given below links.
original url for match pages:
http://www.cricmelive.tv/live/09876/barisal_bulls_vs_chittagong_vikings_t20
now needed url:
http://www.cricmelive.tv/live/09876/barisal_bulls_vs_chittagong_vikings_t20
2. original url for Channel Catgry:
http://www.cricmelive.tv/live/category.php?id=1
now needed url as:
http://www.cricmelive.tv/live/sports
3. original url for Sports Catgry:
http://www.cricmelive.tv/live/index.php?catid=1
now needed url as :
http://www.cricmelive.tv/live/cricket
4. orignal url for Channel Pages:
http://www.cricmelive.tv/live/channel-page.php?cid=45
now needed as :
http://www.cricmelive.tv/live/espn-3-live-streaming
I am new in ur rewrite. I post it again. Help me, how write rewrite url code again original url
I see what you are trying to do but it doesn't work that way. The parameters in the querystring are used at the backend in the sql to find the relevant records in the db using $_GET.
catid=45 does not directly translate to cricket - in the database perhaps catid=1 probably is cricket but the webserver doesn't know this relationship so you would need to alter your sql query such that it used cricket as the parameter in the where clause rather than 1.
For example:
http://www.cricmelive.tv/live/1
that could be expressed easily with a rewrite rule, such as:
RewriteRule ^live/([0-9]+)$ live/index.php?catid=$1 [NC,L]
select * from table where category='cricket'
RewriteRule ^live/([0-9a-zA-Z]+)$ live/index.php?category=$1 [NC,L]

how can get request parameter's value in multi ways in .htaccess url rewriting

I am beginner in PHP. I am using this rule in .htaccess to rewrite my product details page
RewriteRule ^product/([0-9]+)/([a-zA-Z0-9_-]+)$ product-details.php?id=$1&name=$2
When i am calling this URL
http://www.domain.com/product/1008/lorem-ipsum-is-dummy-text?ref=home_page&currency=GBP
page is loading successfully. On this page i can access id and name Request parameter's value but i can't access ref and currency parameter value.
How can i get these parameter's values? Is it possible or not with htaccess?
You have to use QSA flag to append query string.
Have your rule like this
RewriteRule ^product/([0-9]+)/([a-zA-Z0-9_-]+)$ /product-details.php?id=$1&name=$2 [L,QSA]

Hide parameter (query string) in url (htaccess)

How to hide parameters (query_string) in URL but send them to page hidden, not visible in address bar
example:
I have this:
http://localhost/project/company/redeem/category/Shirts/18?category_id=18
I want:
http://localhost/project/company/redeem/category/Shirts.html
But I want to get sent parameter in PHP $_GET['sent']
I tried to redirect to page with no parameters(no query_string) [R] and after that give page some parameters (silently) without [R] redirection (without changing address itself)
I tried to use RewriteRule in .htaccess with different flags and different ways but nothing worked
Please suggest.
As far as i am aware you can only hide the parameter key (in this case 'category_id') using the RewriteEngine:
RewriteEngine On
Then use a RewriteRule like this
RewriteRule ^project/company/redeem/category/Shirts/18/(regex of whatever you expect for your parameter)$ project/company/redeem/category/Shirts/18.php?category_id=$1
Not sure if the first 18 is coincidence or always the same as the category_id value. If it is you can also use
RewriteRule ^project/company/redeem/category/Shirts/(regex of whatever you expect for your parameter)$ project/company/redeem/category/Shirts.php?category_id=$1
If you want to use $_GET the parameters have to be written to the url somewhere. You can only try to hide it.
For example if you know each category by a name you could put those into the url instead of numbers. Lets say category_id 18 is "V-Neck Unisex-Shirts" you could use a url like
http://localhost/project/company/redeem/category/Shirts/V-Uni
and tell your script to use category "V-Uni" instead of "18".
.htaccess:
RewriteRule ^project/company/redeem/category/Shirts/([a-zA-Z-]*)$ project/company/redeem/category/Shirts.php?category=$1

htaccess url rewrite but executes the same page

i have an url like
http://example.com/folder1/folder2/admin_login.php
the above is active page. but i want to show the below url instead of above but functioning the same page.
http://example.com/folder1/folder2/login
So the question is display url-2 in browser but exeuctes url-1
i have tried this code in htaccess file
RewriteEngine on
RewriteRule ^folder1/folder2/admin_login.php$ http://example.com/folder1/folder2/login [NC,L]
When i put url-1 in browser address bar. it will convert into the url-2 but shows Page Not Found
You have it turned around. You want the second url to be in the address bar. That means you have to link to that url. When a request with that url comes to the server, the server has to internally translate that url to a working url. Besides that, you should not have the full url as a rewrite target, because this causes the rule to function as a redirect instead of an internal rewrite.
The following rule should do the trick:
RewriteRule ^folder1/folder2/login/?$ /folder1/folder2/admin_login.php [L]

How to get Dynamic URL With help of .htaccess and PHP for Good SEO

For example i have
3 php pages
www.example.com/page1.php?var1=data1&var2=data2&var3=data3
www.example.com/page2.php?var1=data1&var2=data2&var3=data3
www.example.com/page3.php?var1=data1&var2=data2&var3=data3
For good SEO . I need URL like
www.example.com/page1/data1-data2-data3
www.example.com/page2/data1-data2-data3
www.example.com/page3/data1-data2-data3
I got something URL rewriting with PHP but am confused how to implement it for multiple dynamic PHP pages.
i need all the variables for proper functioning of php pages
Put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^(page1|page2|page3)/([^-]+)-([^-]+)-([^-/]+)/?$ /$1.php?var1=$1&var2=$2&var3=$3 [L,QSA,NE]
In your .htaccess you should add the line:
RewriteRule ^(\w+)/(\w+)-(\w+)-(\w+)$ /$1.php?var1=$2&var2=$3&var3=$4 [QSA]
The first part captures the page name (script name, in your case), then each successive query string parameter. The QSA key tells the redirect to take any additional query string parameters not specified explicitly along with the request.

Categories