将网址重定向到自定义目录

网络精神

我有一个URL https:// facebook。****。in,设置为指向目录/ var / www / html / facebook_app。为此的虚拟主机文件是/etc/apache2/sites-available/facebook.****.in.conf。

我想在URL上添加一个指向另一个自定义目录的路径,这样,

https://facebook.****.in/apis    ->   /var/www/html/apis

我搜索了这个论坛,并在这里找到了一些解决方案

但是我不确定应该在哪里添加别名?应该是default.conf吗?或facebook。****。in.conf文件。

如果它是facebook。****。in.conf文件,我应该如何指定别名?我想将其托管在443端口的SSL上。

facebook。****。in.conf文件:

<VirtualHost *:80>

    ServerAdmin webmaster@localhost
    ServerName facebook.****.in
    ServerAlias facebook.****.in
    DocumentRoot /var/www/html/facebook_app/

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

<VirtualHost *:443>

    ServerAdmin webmaster@localhost
    ServerName facebook.****.in
    ServerAlias facebook.****.in
    DocumentRoot /var/www/html/facebook_app/

    #   SSL Engine Switch:
    #   Enable/Disable SSL for this virtual host.
    SSLEngine on

    #   A self-signed (snakeoil) certificate can be created by installing
    #   the ssl-cert package. See
    #   /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
    #   If both key and certificate are stored in the same file, only the
    #   SSLCertificateFile directive is needed.
    SSLCertificateFile /etc/apache2/ssl/facebook_****_in.crt
    SSLCertificateKeyFile /etc/apache2/ssl/facebook.****.in.key
    SSLCertificateChainFile /etc/apache2/ssl/facebook.****.in.ca-bundle
</VirtualHost>

这是.htaccess文件。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [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 index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]



</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.
# Submitted by: ElliotHaughin

ErrorDocument 404 /index.php
</IfModule>

我有一个index.php文件,它将url参数映射到类和方法。

贡贡格拉

您必须配置文件的两个部分中添加ApacheAliasDirectory伪指令VirtualHostfacebook.****.in.conf以便同时为HTTP和HTTPS连接启用它。

您应该添加的配置代码段必须类似于

Alias "/apis" "/var/www/html/apis"
# Now set directory permission 
<Directory "/var/www/html/apis">
     AllowOverride None
     Options -Indexes +FollowSymLinks

     <IfVersion < 2.3 >
         Order allow,deny
         Allow from all
     </IfVersion>
     <IfVersion >= 2.3>
        Require all granted
     </IfVersion>
 </Directory>

我认为您的Apache Server版本高于2.3,因此仅添加Require all granted语句就可以了,而无需检查版本。我添加它只是为了以防万一。

另外,出于安全性和性能的目的,我还包括了其他一些指令。请在下面找到它们的快速概述

“出于安全和性能的原因,请不要在块中将AllowOverride设置为None以外的任何内容。相反,请找到(或创建)引用您实际打算放置.htaccess文件的目录的块。”

  • Options -Indexes +FollowSymLinks:该-Indexes选项将阻止Web服务器(mod_autoindex具体来说模块)在所需的URL映射到没有目录的目录DirectoryIndex(例如index.html文件)时返回目录的格式化列表除此之外,该+FollowSymLinks选项还允许服务器遵循该目录中的符号链接。您可以Optionshttp://httpd.apache.org/docs/current/mod/core.html#options的Apache Web Server官方文档中获取有关该语句和其他可用选项的更多信息

还请记住为/var/www/html/apis运行Apache服务器的用户(www-data默认情况下在Ubuntu中)目录和文件设置正确的权限,并重新启动Apache服务以使更改生效。

sudo service apache2 restart

更新

如果该目录中没有文件(例如index.php),也可以将DirectoryIndex指令包括在Directory块中index.html

DirectoryIndex index.php

也可以指定多个文件。在这种情况下,将返回找到的第一个文件

DirectoryIndex index.html index.php

有关它的更多信息,请访问http://httpd.apache.org/docs/current/es/mod/mod_dir.html#directoryindex

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Rails重定向到iOS自定义网址

将项目网址重定向到自定义域

Strapi自定义路由重定向到公共目录

PHP将表单重定向到自定义URL

将Github主页重定向到自定义主页

网址以Dot结尾时重定向到自定义404页面

重定向自定义网址上的特定帖子

路由::使用自定义网址(/ products / {name})重定向

Django覆盖自定义登录重定向网址

github项目子目录重定向到自定义域

将Chrome自定义标签重定向到Android应用将关闭该应用

将根/主页重定向到自定义页面会破坏.htaccess中的所有其他重定向

Laravel-根据登录表单上的语言字段将用户重定向到自定义网址

将www重定向到非www以获取自定义URI

无法使用 Razor 页面(net core 3.1)将错误重定向到自定义页面

使用 htacess 将所有自定义页面重定向到专用页面

如何将所有httpError重定向到自定义URL?

如何将URL重定向到自定义IP地址?

如何将* .appspot.com重定向到自定义域

将输出和错误重定向到自定义 PSHostUserInterface

使用自定义目标将所有NLog输出重定向到Serilog

登录后将Laravel Nova重定向到自定义路径

如何将Wordpress注销重定向到自定义URL

将Nginx配置server_name重定向到自定义404错误页面

将Wordpress帖子重定向到自定义php页面

将记录重定向到AWS Route53中的Apigateway自定义域

Django如何将python导入错误重定向到自定义错误页面

如何将文件重定向到自定义 cdn 脚本?

如何将 is_staff 用户重定向到 Django 中的自定义模板?