简体   繁体   中英

Remove .php from URL

Ubuntu 14.04LTS 32bit

It needs to work with \/showthread.php?id=XX ---> \/showthread?id=XX

I've tried these:

While other .htaccess<\/code> code works fine..

<?php 
phpinfo();

Hope helped.

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# For LocalHost !.php
RewriteCond %{HTTP_HOST} !=localhost
RewriteCond %{HTTP_HOST} !=127.0.0.1
RewriteCond %{REMOTE_ADDR} !=127.0.0.1
RewriteCond %{REMOTE_ADDR} !=::1

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=302,L]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

Check this link<\/a> .

RewriteEngine On

# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]

# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]

try this to remove .php extensions completly from your file and to avoid infinite loop:

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]

Maybe this could be a duplicate, but take a look at this:

You may be on the right track. However, it sounds like your .htaccess file is not being executed. Just because a module is activated, does not mean it is available for you in your particular situation.

  • Verify that it is spelled correctly (including the . at the beginning)<\/li>
  • Some servers are going to require executable permissions. So chmod the file to 755.<\/li>
  • It might be set to 'none'. Change this to AllowOverride all<\/code> instead.<\/li>
  • <\/li>
  • <\/li><\/ul>

    One of these should fix it. I would recommend trying between each step so that you can pinpoint where the error occurred. After determining the cause, you may want to go back and restrict some of those AllowOverrides, depending on your needs.

You can try the following.

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php$2 [L]

It works for me:

    #On rewrite
    RewriteEngine On

    # Allow any files or directories that exist to be displayed directly
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d

    # rewrite domain.com/username.php to username
    RewriteRule ^([A-Za-z0-9_-]+)/?$ $1.php [NC,L]
    RewriteRule ^([A-Za-z0-9_-]+)/([A-Za-z0-9]+)/?$ $1/$2.php [NC,L]
    RewriteRule ^([A-Za-z0-9_-]+)/([A-Za-z0-9]+)/([A-Za-z0-9]+)/?$ $1/$2/$3.php [NC,L]

Assuming that .htaccess is being processed, then this super simple .htaccess should work for you:

RewriteEngine on
RewriteRule (.*) $1.php [END]
RewriteEngine on //replacement launch
RewriteCond %{REQUEST_FILENAME} !-d //If the requested object is not a folder
RewriteCond %{REQUEST_FILENAME}\.php -f //If the requested object to append the extension php - file
RewriteRule ^(.*)$ $1.php //make the change from concatenating .php

It's working, You can try this code.

RewriteEngine on

RewriteCond $1 !^(index\.php|resources|robots\.txt)

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

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