简体   繁体   English

.htaccess有多个规则

[英].htaccess with multiple rules

I want to create an htaccess file with the following rules: 我想使用以下规则创建htaccess文件:

I want to redirect: 我想重定向:

http://computingessentials.tk/episodes/6

To: 至:

http://computingessentials.tk/episodes.php?id=6

Same applies with the remaining episode.php ids 其余的Episode.php ID也一样

Next, I want to redirect: 接下来,我要重定向:

http://computingessentials.tk/episode.php?id=56

To: 至:

http://computingessentials.tk/episode/56

Same applies with the remaining episode.php ids 其余的Episode.php ID也一样

And last but not the least, I want to remove all the .php extensions of the files. 最后但并非最不重要的一点,我想删除.php所有.php扩展名。

Since I am farlynew to htaccess i don't really know how to get all of these in an htaccess. 由于我对htaccess还是陌生的,所以我真的不知道如何在htaccess中获取所有这些信息。

Help would be very much appreciated. 帮助将不胜感激。

Make sure your mod rewrite of apache is on and put these rules in .htaccess 确保已对Apache进行mod重写,并将这些规则放入.htaccess中

RewriteEngine on
RewriteRule ^episodes/([0-9]+)$ episodes.php?id=$1 [L]

You can use these 2 rules in your root .htaccess: 您可以在根.htaccess中使用以下2条规则:

Options +FollowSymLinks -MultiViews
RewriteEngine on

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+episodes\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /episodes/%1? [R=301,L]

# internal forward from pretty URL to actual one
RewriteRule ^episodes/([^/.]+)/?$ /episodes.php?id=$1 [L,QSA,NC]

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

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