繁体   English   中英

如何在.htaccess文件中为PHP编写RewriteRule

[英]How to write RewriteRule in .htaccess file for php

我的网站位于任何ip xxx.xxx.xxx.xxx并显示其着陆页。 当我单击任何链接xxx.xxx.xxx.xxx/about它显示404页面未找到 ,如果我手动将index.phpxxx.xxx.xxx.xxx/index.php/about放在其中,则我的xxx.xxx.xxx.xxx/index.php/about页面正在显示。 因此,我应该在.htaccess文件中写些什么,以便当我单击链接xxx.xxx.xxx.xxx/about它时,它将显示我的页面。

目前,我的重写规则是

      <IfModule mod_rewrite.c>

    ############################################
    ## enable rewrites

        Options +FollowSymLinks
        RewriteEngine on

    ############################################
    ## you can put here your magento root folder
    ## path relative to web root

        #RewriteBase /magento/

    ############################################
    ## uncomment next line to enable light API calls processing

    #    RewriteRule ^api/([a-z][0-9a-z_]+)/?$ api.php?type=$1 [QSA,L]

    ############################################
    ## rewrite API2 calls to api.php (by now it is REST only)

        RewriteRule ^api/rest api.php?type=rest [QSA,L]

    ############################################
    ## workaround for HTTP authorization
    ## in CGI environment

        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    ############################################
    ## TRACE and TRACK HTTP methods disabled to prevent XSS attacks

        RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
        RewriteRule .* - [L,R=405]

    ############################################
    ## redirect for mobile user agents

        #RewriteCond %{REQUEST_URI} !^/mobiledirectoryhere/.*$
        #RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
        #RewriteRule ^(.*)$ /mobiledirectoryhere/ [L,R=302]

    ############################################
    ## always send 404 on missing files in these folders

        RewriteCond %{REQUEST_URI} !^/(media|skin|js)/

    ############################################
    ## never rewrite for existing files, directories and links

        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-l

    ############################################
    ## rewrite everything else to index.php

        RewriteRule .* index.php [L]

    </IfModule>

我正在使用以下htaccess代码将我的网址site.com/page.php?id=1重写为site.com/page/1。

RewriteEngine On
RewriteRule ^page/(.*) page.php?id=$1 [L]

如果在主htaccess文件中添加8个重写规则,则可能会增加执行时间。 因此,我计划创建诸如page之类的目录,并将新的htaccess文件放置到每个目录中。

RewriteEngine On
RewriteRule (.*) index.php?id=$1 [L]

但是此代码不起作用。

也许这会帮助您.....................

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM