我正试图使用.htaccess删除服务器上的部分URL。假设我有这个文件夹结构。
根:
- 官方(代码点火器(
- 程序(wordpress(
- .htaccess
/overtical是我访问根域(www.example.com/official
(时的主文件夹。我想从我的URL中删除/official
,我已经用这个.htaccess脚本做到了。
RewriteEngine On
RewriteBase /
RewriteRule ^$ official/ [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((?!official/).+)$ official/$1 [L,NC]
这个脚本的问题是,虽然我可以在没有/official
的情况下访问ci项目,但我仍然可以使用/official
访问它们。我想要的是完全删除/official
,或者重定向它,使URL只显示根域。
我的CI.htaccess是这个
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]
-
创建一个新文件夹
-
构建另一个index.php
-
将.htaccess重定向到新文件夹(1号(内的新索引.php(2号(
-
更改下htaccess中的文件目录
# Disable directory browsing Options All -Indexes # ---------------------------------------------------------------------- # Rewrite engine # ---------------------------------------------------------------------- # Turning on the rewrite engine is necessary for the following rules and features. # FollowSymLinks must be enabled for this to work. <IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On # If you installed CodeIgniter in a subfolder, you will need to # change the following line to match the subfolder you need. # http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase # RewriteBase / # Redirect Trailing Slashes... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} (.+)/$ RewriteRule ^ %1 [L,R=301] # Rewrite "www.example.com -> example.com" RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC] RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L] # Checks to see if the user is attempting to access a valid file, # such as an image or css document, if this isn't true it sends the # request to the front controller, index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([sS]*)$ dir/index.php/$1 [L,NC,QSA] # Ensure Authorization header is passed along RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] </IfModule> <IfModule !mod_rewrite.c> # If we don't have mod_rewrite installed, all 404's # can be sent to index.php, and everything works as normal. ErrorDocument 404 index.php </IfModule> # Disable server signature start ServerSignature Off # Disable server signature end # Disable directory browsing Options All -Indexes
-
index.php
<?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); require '../codeigniter/public/index.php'; ?>
- 目录标记(不推荐(
<Directory "/var/www/html"> AllowOverride AuthConfig Order allow,deny Allow from all </Directory>