使用PHP htaccess的URL重写 [英] PHP url rewriting using htaccess

查看:212
本文介绍了使用PHP htaccess的URL重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  http://www.example.com/justridesbeta/jstride/vehicle
 

  http://www.example.com/justridesbeta/addride
 

使用htaccess的。

目前使用

 < IfModule mod_rewrite.c>
  选项​​+的FollowSymLinks
  RewriteEngine叙述上

  #摆脱的index.php
  的RewriteCond%{REQUEST_URI} /index\.php
  重写规则(。*)的index.php?重写= 2 [L,QSA]

  #重写所有目录,寻找网址
  的RewriteCond%{REQUEST_URI} / $
  重写规则(。*)的index.php?重写= 1 [L,QSA]

  #尽量航线丢失的文件
  的RewriteCond%{} REQUEST_FILENAME!-f
  的RewriteCond%{} REQUEST_FILENAME公共\ / [OR]
  的RewriteCond%{REQUEST_FILENAME} \。(JPG | GIF | PNG | ICO | FLV | HTM |全文| PHP | CSS | JS)$
  重写规则。 -  [L]

  #如果文件不存在,改写指数
  的RewriteCond%{} REQUEST_FILENAME!-f
  的RewriteCond%{} REQUEST_FILENAME!-d
  重写规则^(。*)$的index.php?重写= 1 [L,QSA]



  重写规则^ [A-ZA-Z0-9] + $ justridesbeta / jstride /汽车
  < / IfModule>
 

解决方案

 如果($ _ SERVER ['REQUEST_URI'] =='/ justridesbeta / jstride /车辆)
{
    标题(位置:http://www.example.com/justridesbeta/addride);
    出口;
}
 

如果你的真正的需要了。

http://www.example.com/justridesbeta/jstride/vehicle

to

http://www.example.com/justridesbeta/addride

using htaccess.

Currently using

<IfModule mod_rewrite.c>
  Options +FollowSymLinks
  RewriteEngine On

  # Get rid of index.php
  RewriteCond %{REQUEST_URI} /index\.php
  RewriteRule (.*) index.php?rewrite=2 [L,QSA]

  # Rewrite all directory-looking urls
  RewriteCond %{REQUEST_URI} /$
  RewriteRule (.*) index.php?rewrite=1 [L,QSA]

  # Try to route missing files
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} public\/ [OR]
  RewriteCond %{REQUEST_FILENAME} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
  RewriteRule . - [L]

  # If the file doesn't exist, rewrite to index
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]



  RewriteRule ^[a-zA-Z0-9]+$ justridesbeta/jstride/vehicle
  </IfModule>

解决方案

if ($_SERVER['REQUEST_URI'] == '/justridesbeta/jstride/vehicle')
{
    header("Location: http://www.example.com/justridesbeta/addride");
    exit;
}

if you really need that

这篇关于使用PHP htaccess的URL重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆