简体   繁体   English

尾部斜杠网址.htacces

[英]Trailing slash url .htacces

i was confused about trailing slash, this is script i got from internet 我对斜杠感到困惑,这是我从互联网上获得的脚本

  RewriteEngine On

      RewriteBase /
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_URI} !index.php
      RewriteCond %{REQUEST_URI} !(.*)/$
      RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301]

  Options All -indexes

My question: 我的问题:

1.what function of %{REQUEST_FILENAME} !-f 1. %{REQUEST_FILENAME} !-f功能是什么%{REQUEST_FILENAME} !-f

2.what function of RewriteCond %{REQUEST_URI} !index.php 2. RewriteCond %{REQUEST_URI} !index.php功能是什么

3.what function of RewriteCond %{REQUEST_URI} !(.*)/$ 3. RewriteCond %{REQUEST_URI} !(.*)/$

4.how can i write Rewrite url if the original url like: 4.如果原始网址如下,我该如何写重写网址:

def.php?p=cpanel&m=add_user , def.php?p=cpanel&m=add_user

i want the link above rewrite like cpanel/add_user 我希望上面的链接像cpanel/add_user一样重写

thanks 谢谢

The rule need is this: 规则需要是这样的:

 RewriteEngine On
 RewriteBase /

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^cpanel/([^/]+)/?$ def.php?p=cpanel&m=$1 [L,QSA,NC]

Reference: Apache mod_rewrite Introduction 参考: Apache mod_rewrite简介

  • RewriteCond %{REQUEST_FILENAME} !-f means iif request is not for a valid file RewriteCond %{REQUEST_FILENAME} !-f表示iif请求不是有效文件
  • $1 is backreference to captured string after /cpanel/ $1是对/cpanel/之后捕获的字符串的反向引用
  • QSA (Query String Append) flag preserves existing query parameters while adding a new one. QSA (查询字符串追加)标志在添加新参数时保留了现有查询参数。
  • NC is for ignore case NC用于忽略情况
  • L is for Last rule L代表最后的规则

1.what function of %{REQUEST_FILENAME} !-f 1.%{REQUEST_FILENAME}的功能是什么!

2.what function of RewriteCond %{REQUEST_URI} !index.php 2. RewriteCond%{REQUEST_URI}!index.php的功能是什么

3.what function of RewriteCond %{REQUEST_URI} !(.*)/$ 3. RewriteCond%{REQUEST_URI}!(。*)/ $的功能

You should read the rewrite guide http://httpd.apache.org/docs/2.0/misc/rewriteguide.html 您应该阅读重写指南http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

how can i write Rewrite url if the original url like: 如果原始网址类似,我该如何写重写网址:

def.php?p=cpanel&m=add_user , def.php?p = cpanel&m = add_user,

i want the link above rewrite like cpanel/add_user 我希望上面的链接像cpanel / add_user一样重写

You can use this code in you .htaccess file 您可以在.htaccess文件中使用此代码

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^cpanel/(.*)$ def.php?p=cpanel&m=$1 [L,QSA,NC]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM