重定向网址的重写规则

编程入门 行业动态 更新时间:2024-10-12 05:55:30
本文介绍了重定向网址的重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想应用重写规则来实现这一目标.

I want to apply rewrite rule for achieve this.

current url : localhost/mysite/?userlogin rewrite url : localhost/mysite/userlogin

我想在任何用户打开 localhost/mysite/userlogin 时都喜欢那时,用户必须查看该URL localhost/mysite/?userlogin .

I want to do like when any user open localhost/mysite/userlogin this url, at that time user must get view of localhost/mysite/?userlogin this url.

[注意]:当前的URL现在正在工作.但是我在重写的URL上找不到Object.

[Note] : current url is working right now..But I m getting Object Not found on rewrite url.

谢谢.

推荐答案

如果您使用的是Apache服务器

您可以使用以下内容在Web应用程序根目录中创建.htaccess:

If you are using an Apache server

You can do this creating a .htaccess in your web application root directory with this content:

RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) index.php?p=$1 [QSA]

如果您的根文件夹上有多个站点,例如: |根 | _ web1 | _ web2 | _ web3

If you have more than one site on your root folder, like this: | root |_ web1 |_ web2 |_ web3

您只需要向要启用重写规则的文件夹中添加.htaccess文件,例如: |根 | _ web1 | __ .htaccess | _ web2 | _ web3

you need to add a .htaccess file only to the folder that you want to enable rewrite rules, example: | root |_ web1 |__ .htaccess |_ web2 |_ web3

注意:要使用上述解决方案,您需要启用.htaccess模块 在Apache2中. 在您的 apache2>站点-可用>默认中或 apache2> sites-available>您的配置,设置 AllowOverride 设为全部":

Note: To use the above solution, you need to enable .htaccess module in Apache2. In your apache2>sites-available>default or apache2>sites-available>your_config, set AllowOverride to 'All':

<Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory>

注意:(根据您现有的代码编辑上面的代码.)

您需要将这些行添加到您的nginx服务器配置中!

You need to add these lines to your nginx server config!

if (!-f $request_filename){ set $rule_0 1$rule_0; } if (!-d $request_filename){ set $rule_0 2$rule_0; } if ($rule_0 = "21"){ rewrite /(.*) /index.php?p=$1; }

如果您使用的是Windows IIS服务器

您需要使用以下规则添加一个web.config(我建议在IIS控制面板中使用URLRewrite 2.0来添加这些l

If you are using a Windows IIS Server

You need to add a web.config with these rules (I suggest to use the URLRewrite 2.0 in IIS Control panel to add these l

<rule name="rule 1Z"> <match url="(.*)" /> <action type="Rewrite" url="/index.php?p={R:1}" appendQueryString="true" /> </rule>

更多推荐

重定向网址的重写规则

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

发布评论

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

>www.elefans.com

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