我用Apache新添加了一个Alias,新生成的网址是http://localhost/gyjw/
输入http://localhost/gyjw/会自动跳转到http://localhost/gyjw/index.php
http://localhost/gyjw/index.php这个是我网站的登陆页面,登陆后跳转到http://localhost/gyjw/main.php
现在我想重写http://localhost/gyjw/index.php和http://localhost/gyjw/main.php这两个地址
分别改成http://localhost/index.php和http://localhost/main/?id=101
我自己本想通过修改.htaccess这个文件来进行重写url,但是RewriteCond和RewriteRule这两个弄了半天也没弄好,总是跳出错误页面500,还是不理解啊!
有没有大神能帮我实现呢?url.htaccessapache

解决方案 »

  1.   

    php中include不能直接用url怎么办?
      

  2.   

    没用过Apache重写,不过建议你先测试一下你的正则是否正确
      

  3.   

    <?php
    include ("index.html?fun=000");
    ?>include ("index.html?fun=000");映射的check.php,映射应该没问题,别的链接都是这么写的,只是到了include里面貌似只能用文件不能用url,所以url打不开,应该是属于PHP的一类问题,我就想知道怎么通过虚拟的url来调用并实现其他PHP文件里面的功能。
      

  4.   


    有点乱,你是想通过include函数来实现URL重写功能吧?
    我建议你还是去研究.htaccess,用include函数很少见。
      

  5.   

    可能是我没说清楚吧.htaccess我已经重写完了,现在我想用include调用一个被重写了地址的文件check.php隐藏其真实地址,他重写后的地址是index.html?fun=000,但是直接include ("index.html?fun=000");会出错说不能打开steam,我去google毫无所获。
      

  6.   


    include 是直接调用,index.html?fun=000是经过Apache才转向到check.php
    如果你include 完整的URL,例如http://localhost/index.html?fun=000  估计就正常了,前提是你的include 能引用URL
      

  7.   


    include 是直接调用,index.html?fun=000是经过Apache才转向到check.php
    如果你include 完整的URL,例如http://localhost/index.html?fun=000  估计就正常了,前提是你的include 能引用URL
    功能都开启了,试过了,不行。
    Warning: include() [function.include]: URL file-access is disabled in the server configuration in D:\wamp\web\main.php on line 2Warning: include(http://localhost/gyjw/index.html?fun=000) [function.include]: failed to open stream: no suitable wrapper could be found in D:\wamp\web\main.php on line 2Warning: include() [function.include]: Failed opening 'http://localhost/gyjw/index.html?fun=000' for inclusion (include_path='.;C:\php5\pear') in D:\wamp\web\main.php on line 2php.ini
    ; Whether to allow the treatment of URLs (like http:// or ftp://) as files.
    allow_url_fopen = On; Whether to allow include/require to open URLs (like http:// or ftp://) as files.
    allow_url_include = On
      

  8.   


    include 是直接调用,index.html?fun=000是经过Apache才转向到check.php
    如果你include 完整的URL,例如http://localhost/index.html?fun=000  估计就正常了,前提是你的include 能引用URL
    功能都开启了,试过了,不行。
    Warning: include() [function.include]: URL file-access is disabled in the server configuration in D:\wamp\web\main.php on line 2Warning: include(http://localhost/gyjw/index.html?fun=000) [function.include]: failed to open stream: no suitable wrapper could be found in D:\wamp\web\main.php on line 2Warning: include() [function.include]: Failed opening 'http://localhost/gyjw/index.html?fun=000' for inclusion (include_path='.;C:\php5\pear') in D:\wamp\web\main.php on line 2php.ini
    ; Whether to allow the treatment of URLs (like http:// or ftp://) as files.
    allow_url_fopen = On; Whether to allow include/require to open URLs (like http:// or ftp://) as files.
    allow_url_include = On你确认你配置了正确的PHP.INI?我这里设置allow_url_include = Off 后才会出现这个提示,你phpinfo()看一下你的配置是否正确
      

  9.   

    RewriteEngine on
    RewriteRule ^gate-(.*)-(.*)-(.*).html$ /test/$1.php?mod=$2&act=$3
    ErrorDocument 404 /404.php
    这个是将你的gate-index-Ok-bad.html页面重定向到/test目录下的index.php并给get请求提供两个参数mod=Ok,act=bad
    你自己研究一下吧
      

  10.   

    最后的ErrorDocuemnt是防止恶意输入文件名导致文件名泄漏
    这个将404页面重定向到/404.php这个页面的,具体自己看看吧
      

  11.   

    嗯,解决了,重写的时候用了?把?改成&就好了。不明白是什么原因。可能解析的时候系统认为index.html和index.html?fun=000是重名。
      

  12.   


    截图了,还有别的要设置吗?我也重启了服务。应该没有其他的,我这边都没有问题,不知道你那个是什么情况。
    而且我遇到了新的问题。读取check.php的时候里面的$_SESSION['ss_user_id']数据不存在了
      

  13.   


    你这种乱七八糟的引用会出各种问题的。
    建议你把php文件放在同一个文件夹,引用起来方便快捷。
      

  14.   


    你这种乱七八糟的引用会出各种问题的。
    建议你把php文件放在同一个文件夹,引用起来方便快捷。呃 都在一个文件夹啊。。