简体   繁体   中英

How to write RewriteRule in .htaccess file for php

My site is on any ip xxx.xxx.xxx.xxx and its showing its Landing Page. When i click on any link xxx.xxx.xxx.xxx/about then it showing 404 page not found and if i manually put index.php in it like xxx.xxx.xxx.xxx/index.php/about then my about page is showing. So, What should i write in my .htaccess file so that when i click on my link xxx.xxx.xxx.xxx/about it will show my page.

Currently my rewrite rule is

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

I am using the following htaccess code for rewrite my url site.com/page.php?id=1 to site.com/page/1.

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

If I add 8 rewrite rules to the main htaccess file, it may increase execution time. So I'm planning to create directories like page and place a new htaccess files into each one.

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

But this code doesn't works.

may be this will help you.....................

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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