微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php 动态参数到 url 与 htaccess

如何解决php 动态参数到 url 与 htaccess

我正在尝试通过使用基于斜杠的 url 更改 PHP 参数来使 SEO 友好 url。

我想做
mysite.com/TopList.PHP?tl=ToplistName&fr=2021-02-10&to=2021-02-20 进入: mysite.com/ToplistName/2021-02-20/2021-02-20

我在重写 url 方面取得了成功,但我的包含内容都没有引用正确的目录路径,而且我没有从链接获取 css、js 和文件路径。

这是我现在在 .htaccess 文件中的内容

RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)?$ TopList.PHP?tl=$1&fr=$2&to=$3

谁能帮我在 .htaccess 文件解决这个问题?

解决方法

根据您显示的示例,您能否尝试以下操作。 请确保在测试您的网址之前清除浏览器缓存。

Face f1;
Enemy e1,e2,e3,e4;
Message m1,m2,m3,m4;
int currentTime;
int enemy;


void setup()
{
  size (600,600);
  f1=new Face(50,200,300,255,0); 
  e1 = new Enemy(200,30,-5,0);
  e2=new Enemy(400,40,-8,0);
  e3=new Enemy(100,500,50,-7,0);
  e4=new Enemy(550,400,-6,0);
  m1 = new Message(width/2,height/2,1000,4000,"wear a mask");
  m2 = new Message(width/2,5000,9000,"avoid contacts");
  m3 = new Message(width/2,10000,14000,"wash your hands");
  m4 = new Message(width/2,15000,19000,"stay safe");
  
}
 



void draw()
{
  background (0);
  currentTime = millis();
  f1.display();
  e1.move();
  e1.display();
  e2.display();
  e2.move();
  e3.display();
  e3.move();
  e4.display();
  e4.move();
  m1.setTime(currentTime);
  m2.setTime(currentTime);
  m3.setTime(currentTime);
  m4.setTime(currentTime);
  m1.display();
  m2.display();
  m3.display();
  m4.display();
  
 



  fill(35,20,219);
  rect(200,240,180,30); 
  rect(0,600,10); 
  rect(0,10,600); 
  rect(0,590,10);
  rect(590,600);
  rect(40,20);
  rect(140,20);
  rect(0,220,140);
  rect(0,20);
  rect(80,580,20);
  rect(340,20);
  rect(240,150,20);
  rect(300,50);
  rect(240,380,70);
  rect(390,450,60,15);
  rect(500,90,480,50);
  rect(120,420,80);
  rect(90,20);
  rect(280,60);
  rect(380,20);
  rect(480,280,100);
  rect(450,260,80,20);
  rect(150,120,20);
  rect(275,140,25,40);
  rect(100,270,100);fill(35,100);
  
 
}
 
  
 
     
      
  

  

void keyPressed()
{
  if(key==CODED)
  {
    if(keyCode==LEFT)
    {
     f1.moveLeft();
    }
    if(keyCode==RIGHT)
    {
      f1.moveRight();
    }
    if(keyCode==UP)
    {
     f1.moveUp();
    }
    if(keyCode==DOWN)
    {
     f1.moveDown();
    }
    
 
  }

}
----------------------------------------------
class Eye
{
  int diameter;
  int x;
  int y;
  int grey;
  
  Eye(int d,int xcor,int ycor,int g)
  {
    grey=g;
    diameter=d;
    x=xcor;
    y=ycor;
  }
  void display()
  {
    fill(grey);
    ellipse(x,y,diameter,diameter);
  }
  int getX()
  {
    return x;
  }
  void setX(int xx)
  {
    x=xx;
 }
   int getY()
  {
    return y;
  }
  void setY(int yy)
  {
    y=yy;
 }
 
 
 
 
}
----------------------------------------------
class Enemy
{
  int x;
  int y;
  int diameter;
  int step;
  int r;
  int g;
  int b;
  
  
  Enemy(int a,int b,int c,int d,int rc,int gc,int bc)
  {
    x=a;
    y=a;
    diameter=c;
    step=d;
    r=rc;
    g=gc;
    b=bc;
}
void display()
{ 
  fill(r,g,b);
  stroke(0,255);
  ellipse(x,diameter);
  
}

void move()
{
  y=y+step;
  if(y<diameter)
  step=-step;
  if(y>600)
  step=-step;
}
void moveUp()
{ 
  if(y>=5+diameter/2)
  {
    y=y-5;
  }
}
void moveDown()
{
  if(y<=height-5-diameter/2)
  {
    y=y+5;
  }
}

----------------------------------------------
class Face
{
  int diameter;
  int x;
  int y;
  int r;
  int g;
  int b;
  Eye leftEye;
  Eye rightEye;
  
  Face(int d,int bc)
  {
    diameter=d;
    y=ycor;
    x=xcor;
    r=rc;
    g=gc;
    b=bc;
    leftEye=new Eye(10,x-10,y-10,255);
    rightEye=new Eye(10,x+10,250);
  }
  void display()
  {
    fill(255,b);
    stroke(255,0);
    ellipse(x,diameter);
    leftEye.display();
    rightEye.display();
  }
  void moveLeft()
  {
    if(x>diameter/2)
    {
      x=x-10;
      leftEye.setX(leftEye.getX()-10);
      rightEye.setX(rightEye.getX()-10);
   }
  }
  void moveRight()
  {
    if(x<width-diameter/2)
    {
    x=x+10;
      leftEye.setX(leftEye.getX()+10);
      rightEye.setX(rightEye.getX()+10);
    }
  }
  void moveUp()
{ 
  if(y>=5+diameter/2)
  {
    y=y-10;
    leftEye.setY(leftEye.getY()-10);
    rightEye.setY(rightEye.getY()-10);
  }
}
 
    void moveDown()
{
  if(y<=height-5-diameter/2)
  {
    y=y+10;
    leftEye.setY(leftEye.getY()+10);
    rightEye.setY(rightEye.getY()+10);
    
  }
}
void changeColor()
{
  r=(r+20)%255;
}



  }
  --------------------------------------------
class Message
{
int startTime;
int stopTime;
String str;
int x;
int y;
boolean visible;

Message(int xcor,int t1,int t2,String s)
{
  x = xcor;
  y = ycor;
  startTime = t1;
  stopTime = t2;
  str = s;
  visible = false;
}

void display()
{
  textSize(24);
  if(visible == true)
   {
     text(str,x,y);
   }
}
  
void setTime(int time)
{
    if(time>=startTime && time<= stopTime)
    {
      visible = true;   
    }
    else
    {
      visible = false;   
    }
}

----------------------------------------------
,

我通过执行以下操作解决了这个问题:

  1. 添加到 html:
    <base href="http://example.com/">

  2. 添加到 .htaccess:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    #1 更改完整查询
    重写规则 ^([^/.]+)/([^/.]+)/([^/.]+)/?$ TopList.php?tl=$1&fr=$2&to=$3
    #2 只更改第一个登陆页面
    重写规则 ^([^/.]+)/?$ TopList.php?tl=$1

这给了我以下结果:
mysite.com/TopList.php?tl=ToplistName ==> mysite.com/ToplistName
mysite.com/TopList.php?tl=ToplistName&fr=2021-02-10&to=2021-02-20 ==> mysite.com/ToplistName/2021-02-10/2021-02-20

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。