Converting php by htaccess - .htaccess

How to use .htaccess to rewrite the all URL of .php to / under the folder /hkcompany/
Before rewrite:
www.domain.com/hkcompany/search.php?typeid=1&crno=F1234&name=ABC+Company+有限公司
There are 3 variables for the php url
After rewrite:
www.domain.com/hkcompany/1/F1234/ABC+Company+有限公司
It may be look like:
RewriteEngine On
RewriteRule ^hkcompany/(.*)/(.*)/(.*)/?$ hkcompany/search.php?typeid=$1&crno=$2&name=$3
Thank you for help & support !

Related

My htaccess not working in my website but working in testing site

Finally, I managed to write htaccess code and tested it in http://htaccess.madewithlove.be/ and found its correct.
The way the URL is rewritten in this http://htaccess.madewithlove.be/ is working
but when I use the same htaccess code in my website is not working.
new URL http://192.168.1.190/qjyii2/yii2dev3/frontend/web/login.php
Actual URL http://192.168.1.190/qjyii2/yii2dev3/frontend/web/index.php?r=site/login
Htaccess code
RewriteEngine On
RewriteRule ^qjyii2/yii2dev3/frontend/web/([^/]*)\.php$ /qjyii2/yii2dev3/frontend/web/index.php?r=site/$1 [L]
My mod_rewrite is working fine in server. I did put this htaccess under /www/qjyii2/yii2dev3/ and its not working. Any help is highly appreciated.
If you're placing this in /www/qjyii2/yii2dev3/.htaccess then use this code:
RewriteEngine On
RewriteBase /www/qjyii2/yii2dev3/
RewriteRule ^(frontend/web)/([^/]*)\.php$ $1/index.php?r=site/$2 [L,NC,QSA]
.htaccess is per directory directive and Apache strips the current directory path from RewriteRule URI pattern.

URL Rewriting in. Htaccess

I have a website on a test server and I want to rewrite URL for this website because it is very long
I wish our visitors instead of entering this URL:
http://staging.company.fr/site2.it/s...oject2/public/
enter this URL:
www.monsite.com
I created a file. htaccess:
RewriteEngine On
RewriteRule ^/~(.+) http://www.monsite.com/~$1 [NC,L]
but does not work
While in .htaccess mod_rewrite doesn't match leading slash in a URL since it is applied per directory. Therefore following should work:
RewriteEngine On
RewriteRule ^(.+)$ http://www.monsite.com/$1 [L,R=301,NE]
This will redirect every URL in your existing domain other than home / to monsite.com
Reference: Apache mod_rewrite Introduction

URL rewriting in PHP using .htaccess: How to put `/` in URL?

I have a URL like www.test.com?id=other-flavor&pid=hannycakes.
I did above URL like www.test.com/other-flavor$pid=hannycakes using .Htaccess
but I need www.test.com/other-flavor/hannycakes.
For this If I use / in my URL it can take as a folder.
How resolve my problem. How to put / in URL?
Try this:
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /?id=$1&pid=$2 [L]

How to rewrite URL like this http://localhost/gestor_3.0/index.php?p=cadastros&t=operadoras

How to rewrite URL like this
http://localhost/gestor_3.0/index.php?p=cadastros&t=operadoras
to
http://localhost/gestor_3.0/cadastros/operadoras
using htaccess and mod_rewrite.
To ReWrite your seo frindly url /cadastros/operadoras to the parsing php file
RewriteRule ^gestor_3.0/(.*)/(.*)/?$ /index.php?p=$1&t=$2 [L]

how to write htaccess rewrite rule

Asking for your help:
I want to write a htaccess rewrite rule that will redirect all urls :
accounts.mysubdomain.com/TB/.... -->
accounts.mysubdomain.com/....
can you please help me out?
TIA
Create a .htaccess file in /TB/ directory to redirect to any directory (you can have absolute or relative paths instead of my_dir)
RewriteEngine On
RewriteRule ^TB/(.*)$ /new_dir/$1 [R=301,L]
If you are redirecting everything in the accounts.mysubdomain.com/TB/ to accounts.mysubdomain.com then use the following rule:
RewriteEngine On
RewriteRule ^TB/(.*)$ http://accounts.mysubdomain.com/$1 [R=301,L]

Resources