我要重写URL类似如下:
I want to rewrite the URL like below:
网址:的http://本地主机/ my_site / FILE_NAME =采样
URL: localhost/my_site/?file_name=sample
这是我的网址我想说明它像:
This is my URL I want to show it like:
网址:的http://本地主机/ my_site /样品
URL: 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 localhost/my_site/sample its showing me the list of all sites present in my local that means its taking me to 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的重定向不工作
发布评论