用于删除.php扩展名表单网址,其中包含短划线,如
http://www.sitename.com/here-the-filename-with-dashes.php
http://www.sitename.com/filename.php
to
http://www.sitename.com/here-the-filename-with-dashes
http://www.sitename.com/filename
我已经尝试了几个代码,但没有通过htaccess文件使用。 这里是HTACCESS FILE:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
#RewriteRule ^([a-zA-Z0-9_-\s]+)/$ /$1.php
#RewriteRule ^(.*?)/?$ $1.php
RewriteRule ^(.*)$ $1.php
#RewriteRule ^(.*)$http://www.sitename.ca/?$1.php [L,R=302]
#RewriteRule ^([^\.]+)$ $1.php [NC,L]
#RewriteRule ^([a-z]+)\/?$ $1.php [NC]
#RewriteRule ^([^/]+)/$ $1.php
RewriteCond %{HTTP_HOST} ^sitename.com [NC]
RewriteRule ^(.*)$ http://www.sitename.com/$1 [L,R=301]
RewriteRule ^index.php$ http://www.sitename.com/ [R=301,L]
答案 0 :(得分:0)
你走在正确的道路上。
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sitename.com$ [NC]
RewriteRule ^ http://www.sitename.com%{REQUEST_URI} [L,R=301]
RewriteRule ^index.php$ http://www.sitename.com/ [R=301,L]
RewriteCond %{THE_REQUEST} ^GET\ /(.+)\.php [NC]
RewriteRule ^ /%1 [QSA,R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ /$1.php [L]