通过htaccess的重定向不工作 [英] Redirection through htaccess not working

查看:88
本文介绍了通过htaccess的重定向不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要重写URL类似如下:

I want to rewrite the URL like below:

网址:的http://本地主机/ my_site / FILE_NAME =采样

URL: http://localhost/my_site/?file_name=sample

这是我的网址我想说明它像:

This is my URL I want to show it like:

网址:的http://本地主机/ my_site /样品

URL: http://localhost/my_site/sample

这意味着我要删除file_name参数和获取参数值,并将其设置的URL,设置此我使用了下面code:

that means I want to remove file_name parameter and get the parameter value and set it in URL, for setting this I have used below code:

RewriteEngine On
RewriteBase /my_site/
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteRule ^(.*)$ /?file_name=$1 [QSA,L]

但它不工作,当我键入的http://本地主机/ my_site /样品它显示我的所有站点present在我的地方,这意味着它带我到<强名单> HTTP://本地主机,而不是需要的页面。有什么错,我在做什么?

But its not working, when I type http://localhost/my_site/sample its showing me the list of all sites present in my local that means its taking me to http://localhost instead of require page. What wrong I am doing?

请帮忙,在此先感谢

推荐答案

假设 mysite的文件夹下的的DocumentRoot 。添加到您的

Assuming that mysite folder is under DocumentRoot. add this to your

RewriteEngine On
RewriteBase /

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

RewriteCond %{REQUEST_URI} !-f 
RewriteCond %{REQUEST_URI} !\.\w+$
RewriteCond %{REQUEST_URI} !/$ 
RewriteRule (.*) /$1/ [R,L]

RewriteCond %{REQUEST_URI} ^/(my_site)/([\w\d-]+)/$ [NC]
RewriteRule ^ %1/?file_name=%2 [L,QSA]

RewriteCond %{QUERY_STRING} !^$
RewriteCond %{QUERY_STRING} (?:(.*)&)?file_name=([\w\d-]+)(.*) [NC]
RewriteRule ^(my_site) $1/%2/?%1%3 [L,R]


有关服务器端:


For server side:

RewriteCond %{REQUEST_URI} ^/([\w\d-]+)/$ [NC]
RewriteRule ^ /?file_name=%1 [L,QSA]

RewriteCond %{QUERY_STRING} !^$
RewriteCond %{QUERY_STRING} (?:(.*)&)?file_name=([\w\d-]+)(.*) [NC]
RewriteRule ^ %2/?%1%3 [L,R]

这篇关于通过htaccess的重定向不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆