Remove php extension of website with htaccess

前端 未结 2 2002
星月不相逢
星月不相逢 2020-12-22 04:31

I have these links on my website:

http://crw4u.be/werkgever.php (I can only add 2 urls in my question, since i\'m a n00b)

I added a code to htaccess so I can

相关标签:
2条回答
  • 2020-12-22 05:24

    Try this Rule:-

    RewriteEngine on 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME}\.php -f 
    RewriteRule ^(.*)$ $1.php
    

    Here is basic description for how rules are working:-

    Regular Expressions

    . (any character)
    * (zero of more of the preceding)
    + (one or more of the preceding)
    {} (minimum to maximum quantifier)
    ? (ungreedy modifier)
    ! (at start of string means "negative pattern")
    ^ (start of string, or "negative" if at the start of a range)
    $ (end of string)
    [] (match any of contents)
    - (range if used between square brackets)
    () (group, backreferenced group)
    | (alternative, or)
    \ (the escape character itself)
    

    Using regular expressions, it is possible to search for all sorts of patterns in URLs and rewrite them when they match

    Flags

    Flags are added to the end of a rewrite rule to tell Apache how to interpret and handle the rule. They can be used to tell apache to treat the rule as case-insensitive, to stop processing rules if the current one matches, or a variety of other options. They are comma-separated, and contained in square brackets. Here's a list of the flags, with their meanings.

    C (chained with next rule)
    CO=cookie (set specified cookie)
    E=var:value (set environment variable var to value)
    F (forbidden - sends a 403 header to the user)
    G (gone - no longer exists)
    H=handler (set handler)
    L (last - stop processing rules)
    N (next - continue processing rules)
    NC (case insensitive)
    NE (do not escape special URL characters in output)
    NS (ignore this rule if the request is a subrequest)
    P (proxy - i.e., apache should grab the remote content specified in the substitution section and return it)
    PT (pass through - use when processing URLs with additional handlers, e.g., mod_alias)
    R (temporary redirect to new URL)
    R=301 (permanent redirect to new URL)
    QSA (append query string from request to substituted URL)
    S=x (skip next x rules)
    T=mime-type (force specified mime type)
    

    Exceptions and Special Cases

    Rewrite conditions can be tested in a few different ways - they do not need to be treated as regular expression patterns, although this is the most common way they are used. Here are the various ways rewrite conditons can be processed:

    <Pattern (is test string lower than pattern)
    >Pattern (is test string greater than pattern)
    =Pattern (is test string equal to pattern)
    -d (is test string a valid directory)
    -f (is test string a valid file)
    -s (is test string a valid file with size greater than zero)
    -l (is test string a symbolic link)
    -F (is test string a valid file, and accessible (via subrequest))
    -U (is test string a valid URL, and accessible (via subrequest))
    

    Hope it will help you :)

    0 讨论(0)
  • 2020-12-22 05:25

    Add this code also, It will let you to access directories.

    RewriteCond %{REQUEST_FILENAME} !-d
    
    0 讨论(0)
提交回复
热议问题