[英]how to rewrite SEO-friendly url markep in htaccess
I am trying to convert my URL in to SEO Friendly url. 我正在尝试将我的URL转换为SEO友好URL。 I do not have much knowledge about htaccess rewrite rules, URL is:
我对htaccess重写规则了解不多,URL为:
https://www.zesteve.com/search.php?loc=Guntur&q=manjunath-cake-shop
the URL should be 该网址应为
https://www.zesteve.com/Guntur/manjunath-cake-shop
I have tried this: 我已经试过了:
RewriteEngine On
RewriteCond $1 ^search
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ search.php?q=$1 [L,QSA]
I got the result as 我得到的结果是
https://www.zesteve.com/search?loc=Guntur&q=manjunath-cake-shop
Edit 编辑
I am using jquery to redirect 我正在使用jQuery重定向
window.location.href = 'search?loc=' + location[0] + '&q='+ search_term;
If any body look for same solution. 如果有任何身体寻找相同的解决方案。 Here is my answer
这是我的答案
First it should redirect and convert to SEO Friendly URL 首先,它应该重定向并转换为SEO友好URL
# Redirect to SEO Friendly Url
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(?:search\.php)?\?loc=([^\s]+)&q=([^\s]+)? [NC]
RewriteRule ^ /%1/%2? [R=301]
and now Set URL 现在设置URL
RewriteCond $1 ^
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ search.php?loc=$1&q=$2 [L,QSA]
It solved my problem. 它解决了我的问题。
https://www.zesteve.com/search.php?loc=Guntur&q=manjunath-cake-shop
above URL is now 上面的URL现在是
https://www.zesteve.com/Guntur/manjunath-cake-shop
I don't want to show search.php page in URL 我不想在URL中显示search.php页面
RewriteRule ^([^/]*)/([^/]*)$ /search.php?loc=$1&q=$2 [L]
Use this in your .htaccess
file: 在您的
.htaccess
文件中使用此命令:
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /search.php?loc=$1&q=$2 [L]
It will leave you with the URL: https://www.zesteve.com/Guntur/manjunath-cake-shop
. 它将为您提供以下URL:
https://www.zesteve.com/Guntur/manjunath-cake-shop
: https://www.zesteve.com/Guntur/manjunath-cake-shop
。 Just make sure you clear your cache before you test this. 只需确保在测试前清除缓存即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.