重定向网址的重写规则 [英] Rewrite rule for redirect url

查看:95
本文介绍了重定向网址的重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to apply rewrite rule for achieve this.

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

rewrite url : http://localhost/mysite/userlogin

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

I want to do like when any user open http://localhost/mysite/userlogin this url, at that time user must get view of http://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>

这篇关于重定向网址的重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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