.htaccess 使用htaccess重写

.htaccess 使用htaccess重写,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,这就是我要做的。我有这些网址,旧的和新的形式 site.com/video.php -> site.com/video site.com/index.php?cat_id=1 -> site.com/some-cat-name 这是我的htaccess文件,它只有在最后两个文件中的一个被注释时才能工作 Options +FollowSymLinks RewriteEngine on RewriteBase / RewriteRule ^\.htaccess$ - [F] Rewr

这就是我要做的。我有这些网址,旧的和新的形式

site.com/video.php -> site.com/video
site.com/index.php?cat_id=1 -> site.com/some-cat-name
这是我的htaccess文件,它只有在最后两个文件中的一个被注释时才能工作

Options +FollowSymLinks
RewriteEngine on
RewriteBase / 
RewriteRule ^\.htaccess$ - [F]
RewriteCond $1   !^(index\.php|img|js|css|admin|robots\.txt)
RewriteRule ^video$   /videos.php/$1 [L] 
#RewriteRule ^(.*)$   /index.php/$1 [L] 
如果这两个都处于活动状态,服务器将返回错误500

RewriteRule ^video$   /videos.php/$1 [L] 
RewriteRule ^(.*)$   /index.php/$1 [L] 
我的逻辑是,如果url中的第一个匹配视频重定向到videos.php并在这一行下全部忘记,但似乎是以另一种方式。有人能解释一下如何在index.php,tnx中使用一些预先定义的URL和所有其他URL。

由于您的规则在该规则中循环,您将获得500(内部服务器错误):

RewriteRule ^(.*)$   /index.php/$1 [L] 
要修复此规则,请按如下方式使用.htaccess:

Options +FollowSymLinks
RewriteEngine on
RewriteBase / 
RewriteRule ^\.htaccess$ - [F]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1   !^(index\.php|img|js|css|admin|robots\.txt)
RewriteRule ^video$   /videos.php/$1 [L] 

# ignore existing files and directories from rewrite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$   /index.php/$1 [L]