doulian8485 2016-02-26 08:28
浏览 107

重写重定向网址的规则

I want to apply rewrite rule for achieve this.

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

rewrite 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.

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

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dongnan1989 2016-02-26 08:39
    关注

    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]
    

    If you have more than one site on your root folder, like this:
    | root
    |_ web1
    |_ 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

    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>
    

    Note: (Edit the code above according to your existing code.)

    If you are using a Nginx server

    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;
    }
    

    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>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看