简体   繁体   English

.htaccess用于多个重写规则

[英].htaccess for multiple rewrite rules

I wanted to create an htaccess file to remove the .php extension and change course.php?id=1 to course/1 . 我想创建一个htaccess文件以删除.php扩展名,并将course.php?id=1更改为course/1 But that does not seem to work out. 但这似乎无法解决。 Can any one correct my htaccess?(I am quite new to writing htaccess files) 任何人都可以纠正我的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

Keep it this way: 保持这种方式:

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM