我想用重写规则 让访问网站时,只要是根目录下写的东西都是参数,即使存在此文件或文件夹
例如:http://www.XXXX.com/abcd.php  或者  http://www.XXXX.com/ABCD/   两个
假如网站中存在此文件和文件夹  abcd.php 和 ABCD  就像网址访问时, abcd.php 和 ABCD  都变成参数,像传值一样“abcd.php”和“ABCD”都是字符串,进行处理。
  这种重写规则怎么写?

解决方案 »

  1.   


    又见LS广告。点击查看此帖!注意的问题:
    1.Apache服务器的重写文件时.htaccess,IIS重写的文件时httpd.ini。都必须开启支持rewrite的功能。
    2.如果存在一个 /ABCD.php 文件,而用户输入 /ABCD的时候可能不会重写到与之同名的文件上面而是不停的循环或者不执行。
    httpd.ini[ISAPI_Rewrite]# 3600 = 1 hour
    CacheClockRate 3600RepeatLimit 32RewriteRule (.*) /abcd.php\?$1 [NC,R=301]
    .htaccess<IfModule mod_expires.c>
    ExpiresByType text/html A1
    </IfModule>
    <IfModule mod_rewrite.c>
    RewriteEngine On
    #RewriteBase /#RewriteRule ^(.*)$ /abcd.php?$1 [R=301,L]
    </IfModule>
    你说的自动判断,估计实现有点难,坐等高人。
      

  2.   


    呃,不小心注释掉了那两行:<IfModule mod_expires.c>
    ExpiresByType text/html A1
    </IfModule>
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /RewriteRule ^(.*)$ /abcd.php?$1 [R=301,L]
    </IfModule>
      

  3.   


    RewriteRule ^([^\.]*)$ $1\.php
      

  4.   

    RewriteRule ^([^\.]*)$ $1\.php
    //http://www.mydir.com/ad(如果有ad目录则会进入ad目录,如果没有ad目录则会访问ad.php)
      

  5.   

    如果参数也这样写呢
    http://www.mydir.com/ad/id/1
    还想用$_GET获取值,比如$_GET['id']
      

  6.   

    这个说得挺费劲的,很多框架就这样子http://topic.csdn.net/u/20100331/21/0ac266ec-1910-483b-9f91-4d781a773b96.html.htaccess文件:
    RewriteEngine On# uncomment the following line, if you are having trouble
    # getting no_script_name to work
    #RewriteBase /# we skip all files with .something
    #RewriteCond %{REQUEST_URI} \..+$
    #RewriteCond %{REQUEST_URI} !\.html$
    #RewriteRule .* - [L]# we check if the .html version is here (caching)
    RewriteRule ^$ index.html [QSA]
    RewriteRule ^([^.]+)$ $1.html [QSA]
    RewriteCond %{REQUEST_FILENAME} !-f# no, so we redirect to our front web controller
    RewriteRule ^(.*)$ index.php [QSA,L]这样所有
    http://www.mydir.com/ad/id/1
    会变成
    http://www.mydir.com/index.php/ad/id/1