可以清理.htaccess规则吗?

时间:2019-08-05 16:54:33

标签: .htaccess

我正在帮助一个项目,并注意到.htaccess文件中的以下规则:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^old-projectdomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.old-projectdomain.com$
RewriteRule (.*)$ https://www.new-projectdomain.com/$1 [R=301,L]

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

我不是这方面的专家,但它看起来有点多余,我只是不能动动手指,可以简化吗?

1 个答案:

答案 0 :(得分:0)

您可以使用单个规则,如下所示:

using UnityEngine;
using System.Collections.Generic;
using System.Collections;

// https://www.youtube.com/watch?v=KKgtC_Gy65c&list=PLPV2KyIb3jR42oVBU6K2DIL6Y22Ry9J1c&index=9
// https://www.youtube.com/watch?v=4ivFemmpYus&list=PLPV2KyIb3jR42oVBU6K2DIL6Y22Ry9J1c&index=10
// https://www.youtube.com/watch?v=1KdS0QzyhCg&list=PLPV2KyIb3jR42oVBU6K2DIL6Y22Ry9J1c&index=11

public class Weapon : MonoBehaviour
{
    public float fireRate = 0;
    public int Damage = 10;
    public LayerMask whatToHit;

    public Transform BulletTrailPrefab;
    public Transform MuzzleFlashPrefab;
    float timeToSpawnEffect = 0;
    public float effectSpawnRate = 10;

    public float lifeTime; 
    float timeToFire = 0;
    Transform firePoint;

    // Use this for initialization
    void Awake()
    {
        firePoint = transform.Find("FirePoint");
        if (firePoint == null)
        {
            Debug.LogError("No firePoint? WHAT?!");
        }
    }

    // Update is called once per frame
    void Update()
    {
        if (fireRate == 0)
        {
            if (Input.GetButtonDown("Fire1"))
            {
                Shoot();
            }
        }
        else
        {
            if (Input.GetButton("Fire1") && Time.time > timeToFire)
            {
                timeToFire = Time.time + 1 / fireRate;
                Shoot();
            }
        }
    }

    void Shoot()
    {
        Vector2 mousePosition = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y);
        Vector2 firePointPosition = new Vector2(firePoint.position.x, firePoint.position.y);
        RaycastHit2D hit = Physics2D.Raycast(firePointPosition, mousePosition - firePointPosition, 100, whatToHit);

        if (Time.time >= timeToSpawnEffect)
        {
            Effect();
            timeToSpawnEffect = Time.time + 1 / effectSpawnRate;
        }

        Debug.DrawLine(firePointPosition, (mousePosition - firePointPosition) * 100, Color.cyan);
        if (hit.collider != null)
        {
            Debug.DrawLine(firePointPosition, hit.point, Color.red);
            Debug.Log("We hit " + hit.collider.name + " and did " + Damage + " damage.");

            Debug.Log(hit.collider.name);  // This is a test to detect the collision.

            Enemy enemy = hit.collider.GetComponent<Enemy>();

            Debug.Log(enemy); // This is a test to detect that the enemy was created.

            if (enemy != null)
            {
                Debug.Log("Inside the loop"); // This is  test to detect if inside the loop...
                enemy.DamageEnemy(Damage);
                Debug.Log("We hit " + hit.collider.name + " and did " + Damage + " damage.");
            }
        }
    }

    void Effect()
    {
        Instantiate(BulletTrailPrefab, firePoint.position, firePoint.rotation);
        Transform clone = Instantiate(MuzzleFlashPrefab, firePoint.position, firePoint.rotation) as Transform;  // why cast?
        clone.parent = firePoint;
        float size = Random.Range(0.6f,0.9f);
        clone.localScale = new Vector3(size, size, 0f);
        Destroy(clone.gameObject, lifeTime);
    }
}
相关问题