我在 yii 框架中工作并尝试使用 htaccess 文件重写 url 这是我的文件(第一步我试图使用一个简单的规则)
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^carguide$ MainModel/index/304 [NC,L]
# otherwise forward it to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
# otherwise forward it to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
我想将 url carguide 重写为 mainModel/index/304,但是我尝试过的 yii 没有收到原始 url 并引发 404 错误。
这是日志文件:
strip per-dir prefix: C:/xampp/htdocs/cars/carguide -> carguide
applying pattern '^carguide$' to uri 'carguide'
RewriteCond: input='C:/xampp/htdocs/cars/carguide' pattern='!-f' => matched
RewriteCond: input='C:/xampp/htdocs/cars/carguide' pattern='!-d' => matched
rewrite 'carguide' -> 'MainModel/index/304'
add per-dir prefix: MainModel/index/304 -> C:/xampp/htdocs/cars/MainModel/index/304
strip document_root prefix: C:/xampp/htdocs/cars/MainModel/index/304 -> /cars/MainModel/index/304
internal redirect with /cars/MainModel/index/304 [INTERNAL REDIRECT]
add path info postfix: C:/xampp/htdocs/cars/MainModel -> C:/xampp/htdocs/cars/MainModel/index/304
strip per-dir prefix: C:/xampp/htdocs/cars/MainModel/index/304 -> MainModel/index/304
applying pattern '^carguide1$' to uri 'MainModel/index/304'
add path info postfix: C:/xampp/htdocs/cars/MainModel -> C:/xampp/htdocs/cars/MainModel/index/304
strip per-dir prefix: C:/xampp/htdocs/cars/MainModel/index/304 -> MainModel/index/304
applying pattern '.' to uri 'MainModel/index/304'
RewriteCond: input='C:/xampp/htdocs/cars/MainModel' pattern='!-f' => matched
RewriteCond: input='C:/xampp/htdocs/cars/MainModel' pattern='!-d' => matched
rewrite 'MainModel/index/304' -> 'index.php'
add per-dir prefix: index.php -> C:/xampp/htdocs/cars/index.php
strip document_root prefix: C:/xampp/htdocs/cars/index.php -> /cars/index.php
internal redirect with /cars/index.php [INTERNAL REDIRECT]
strip per-dir prefix: C:/xampp/htdocs/cars/index.php -> index.php
applying pattern '^carguide$' to uri 'index.php'
strip per-dir prefix: C:/xampp/htdocs/cars/index.php -> index.php
applying pattern '.' to uri 'index.php'
RewriteCond: input='C:/xampp/htdocs/cars/index.php' pattern='!-f' => not-matched
pass through C:/xampp/htdocs/cars/index.php
我试图更改标志,添加一个 RewiteBase。