我想创建一个htaccess文件来删除.php
扩展名,并将course.php?id=1
更改为course/1
。但这似乎没有成功。任何人都可以纠正我的htaccess吗?(我对编写htaccess文件很新)
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
# If request is for a file that does actually exist, don't rewrite.
RewriteCond %{REQUEST_FILENAME} !-f
# If request is for a directory that does actually exist, don't rewrite.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/course/(.*)$ /course.php?id=$1 [NC]
Options -Indexes
答案 0 :(得分:1)
保持这种方式:
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# add a trailing slash
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^(.+)$ $1/ [R=301,L]
RewriteRule ^course/([^/]+)/?$ course.php?id=$1 [NC,L,QSA]
RewriteRule ^([^/]+)/$ $1.php [L]
RewriteRule ^([^/]+)/([^/]+)/$ $1/$2.php [L]