[英]How to use RewriteRule in htaccess using XAMPP
How do I get rid of the folder name using .htaccess and XAMPP. 如何使用.htaccess和XAMPP删除文件夹名称。
I saved the folder in --> xampp/htdocs/myproject 我将文件夹保存在-> xampp / htdocs / myproject
In myproject folder there are an index.php
and .htaccess
files. 在myproject文件夹中,有一个index.php
和.htaccess
文件。
RewriteEngine On
RewriteBase /myproject/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
index.php index.php
<h1>index</h1>
<?php
var_dump($_SERVER["REQUEST_URI"]);
This redirects me to the index file but when i var_dump requested uri i'm getting also myfoler name. 这将我重定向到索引文件,但是当我var_dump请求uri时,我也得到了myfoler名称。
example: 例:
http://localhost/myproject/contact
i'm getting --> /myproject/contact
我正在-> /myproject/contact
Is this possible to get rid of this foldername/path using .htaccess ? 是否可以使用.htaccess删除此文件夹名称/路径? In this case the /myproject/
. 在这种情况下, /myproject/
。
RewriteRule ^myproject/(.*)$ $1
This will take any url of the pattern "myproject/whatever" and rewrite it as "whatever". 这将采用模式“ myproject / whatever”的任何URL,并将其重写为“ whatever”。 The string (.*) tells .htaccess to take everything after "myproject/" and store it in a backreference, which is referred to in the rewrite portion of the rule as $1. 字符串(。*)告诉.htaccess将“ myproject /”之后的所有内容存储在反向引用中,该反向引用在规则的重写部分中称为$ 1。 Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.