0

I want to remove the .php from the url through htaccess file. for example home.php to home I'm using the following rewrite rule in htaccess file.

    RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]

I also want to assign the login as index. How can I change it.

4

2 に答える 2

2

これは、.php 拡張子を非表示にするために使用できるコードです。

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

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

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ $1.php [L,NC]
于 2012-05-22T21:39:11.657 に答える
0
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
# Replace html with your file extension, eg: php, htm, asp

URL の末尾にスラッシュを追加するには (例: http://www.example.com/about-us/に移動するにはhttp://www.example.com/about-us.html )

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^/]+)/$ $1.html 

# Forces a trailing slash to be added
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
于 2012-05-22T21:37:45.120 に答える