zoukankan      html  css  js  c++  java
  • 在xampp+window环境下配置yii的url美化

    在整个项目目录中protected和themes文件夹下都有一个.htaccess,保证这两个文件夹不会被单独访问到

    yii原始的url看来很复杂而且对seo并不友好

    可以通过以下的配置来美化url

    在protected/config/main.php中配置

     1 'urlManager'=>array(
     2             'urlFormat'=>'path',
     3             'rules'=>array(
     4                 '<controller:w+>/<id:d+>'=>'<controller>/view',
     5                 '<controller:w+>/<action:w+>/<id:d+>'=>'<controller>/<action>',
     6                 '<controller:w+>/<action:w+>'=>'<controller>/<action>',
     7             ),
     8             'showScriptName'=>false, 
     9             'urlSuffix'=>'.html' //自定义后缀
    10         ),

    在入口文件的根目录下创建一个.htaccess文件(来自官网源码)

     1 Options +FollowSymLinks
     2 IndexIgnore */*
     3 RewriteEngine on
     4 
     5 # if a directory or a file exists, use it directly
     6 RewriteCond %{REQUEST_FILENAME} !-f
     7 RewriteCond %{REQUEST_FILENAME} !-d
     8 
     9 # otherwise forward it to index.php
    10 RewriteRule . index.php

    如果xampp开启的虚拟主机,则修改apache/conf/extra/http-vhost.conf,增加

     1 <VirtualHost *:80>
     2     DocumentRoot "E:/yourwebroot"
     3     ServerName yourwe.com
     4     <Directory "E:/yourwebroot">
     5         Options Indexes MultiViews FollowSymLinks
     6         AllowOverride All
     7         Order allow,deny
     8         Allow from all
     9     </Directory>
    10 </VirtualHost>

    重启apache,即可以做到最简单的yii url rewrite

  • 相关阅读:
    17. Letter Combinations of a Phone Number
    16. 3Sum Closest
    15. 3Sum
    14. Longest Common Prefix
    13. Roman to Integer
    12. Integer to Roman
    11. Container With Most Water
    10. Regular Expression Matching
    9. Palindrome Number
    8. String to Integer (atoi)
  • 原文地址:https://www.cnblogs.com/leftice/p/3776595.html
Copyright © 2011-2022 走看看