通过htaccess的重定向不工作

编程入门 行业动态 更新时间:2024-10-22 14:03:54
本文介绍了通过htaccess的重定向不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我要重写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的重定向不工作

本文发布于:2023-10-31 13:01:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546162.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   工作   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!