[英]How to URL redirect/rewrite using the .htaccess file
How to write .htaccess rewriterule for the below URL. 如何为以下URL编写.htaccess重写程序。 I am new to htaccess.
我是htaccess的新手。
http://velloredentists.com/search.php?s=VASAN+DENTAL+CLINIC&c=Bagayam ) http://velloredentists.com/search.php?s=VASAN+DENTAL+CLINIC&c=Bagayam )
to 至
http://velloredentists.com/search/VASAN+DENTAL+CLINIC/Bagayam http://velloredentists.com/search/VASAN+DENTAL+CLINIC/Bagayam
Please help me to solve this. 请帮我解决这个问题。
1 - First you need to check if the file .htaccess
exists in the root of your website. 1-首先,您需要检查
.htaccess
文件是否在网站的根目录中。
2 - If the file .htaccess
exists, download it from your site, add the lines below to the end of the file, and upload the modified file back to your site. 2-如果文件
.htaccess
存在,请从您的站点下载该文件,在文件末尾添加以下几行,然后将修改后的文件上传回您的站点。 Please make a copy of the original file .htaccess
. 请复制原始文件
.htaccess
。 So if anything goes wrong, you may restore the original file. 因此,如果出现任何问题,您可以还原原始文件。
3 - If the file .htaccess
does not exist, create a new file .htaccess
and add the lines below to it. 3-如果文件
.htaccess
不存在,请创建一个新文件.htaccess
并在其下添加以下行。 Then upload it to the root of your website. 然后将其上传到您网站的根目录。 You may delete it if anything goes wrong.
如果出现任何问题,可以将其删除。
Add the following lines to .htaccess
: .htaccess
添加到.htaccess
:
RewriteEngine On
RewriteRule ^search/([^/]*)/([^/]*)\.html$ /search.php?s=$1&c=$2 [L]
This worked on my apache server : 这适用于我的apache服务器:
RewriteEngine On
#Redirect "/search.php?s=foo&c=bar to
#/search/foo/bar
RewriteCond %{THE_REQUEST} /search.php\?s=([^&]+)&c=([^\s]+) [NC]
#Rewrite "/search/foo/bar" to
#"/search.php?s=foo&c=bar"
RewriteRule ^ /search/%1/%2? [NC,R,L]
RewriteRule ^search/([^/]+)/([^/]+)/?$ /search.php?s=$1&c=$2 [QSA,L,NC]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.