2017-08-31 93 views
0

我在Ubuntu/Apache服务器上有两个网站。 一个是在目录为什么网址中缺少斜杠添加:8080重定向?

/var/www/html/dir1 

,并且被配置为与活化FollowSymlink选项中的Apache虚拟服务器。答复

http://example.com 

二是

/var/www/html/dir2 

网页的index.html为了得到一个简单的方法来第二友情链接的URL

http://example.com/dir2 

我做了内部的软链接/ var/www/html/dir1到/ var/www/html/dir2命名为dir1,一切正常。 参观

http://example.com/dir2/ 

导致在/ var/www/html等/ DIR2页面的index.html。

到目前为止这么好。

虽然,参观

http://example.com/dir2 

(注意没有最后的斜线的) 导致重定向到

http://example.com:8080/dir2/ 

为什么在这种情况下,端口被添加?我怎样才能轻松删除它?

编辑:我需要删除端口,因为从index.html一些发布请求和:8080部分导致我一些Cors问题。

编辑:虚拟主机的conf

<VirtualHost *:8080> 
    DocumentRoot "/var/www/dir1/drupal" 
    ErrorLog /var/log/apache2/dir1-error.log 
    CustomLog /var/log/apache2/dir1-access.log combined 
    <Directory "/var/www/dir1/drupal/"> 
     Options ExecCGI FollowSymLinks 
     AllowOverride all 
     Allow from all 
     Order allow,deny 
    </Directory> 
</VirtualHost> 

htaccess的Dir1中

# 
# Apache/PHP/Drupal settings: 
# 

# Protect files and directories from prying eyes. 
<FilesMatch "/fb/|/phpMyAdmin/|\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$"> 
    Order allow,deny 
</FilesMatch> 

# Don't show directory listings for URLs which map to a directory. 
Options -Indexes 

# Follow symbolic links in this directory. 
Options +FollowSymLinks 

# Make Drupal handle any 404 errors. 
ErrorDocument 404 /index.php 

# Set the default handler. 
DirectoryIndex index.php index.html index.htm 

# Override PHP settings that cannot be changed at runtime. See 
# sites/default/default.settings.php and drupal_initialize_variables() in 
# includes/bootstrap.inc for settings that can be changed at runtime. 

# PHP 5, Apache 1 and 2. 
<IfModule mod_php5.c> 
    php_flag magic_quotes_gpc     off 
    php_flag magic_quotes_sybase    off 
    php_flag register_globals     off 
    php_flag session.auto_start    off 
    php_value mbstring.http_input    pass 
    php_value mbstring.http_output   pass 
    php_flag mbstring.encoding_translation off 

    php_value upload_max_filesize 100M 
    php_value post_max_size 100M 
</IfModule> 

# Requires mod_expires to be enabled. 
<IfModule mod_expires.c> 
    # Enable expirations. 
    ExpiresActive On 

    # Cache all files for 2 weeks after access (A). 
    ExpiresDefault A1209600 

    <FilesMatch \.php$> 
    ExpiresActive Off 
    </FilesMatch> 
</IfModule> 

# Various rewrite rules. 
<IfModule mod_rewrite.c> 
    RewriteEngine on 

    RewriteRule "(^|/)\." - [F] 

    RewriteRule ^js\/(.*)$ /sites/all/modules/ets/jslib/$1 [L] 
    RewriteRule (.*)jslib\/\d+\/(.*)$ $1jslib/$2 [L,QSA] 
    RewriteRule (.*)experiments\/\d+\/(.*)$ $1experiments/$2 [L,QSA] 
    RewriteRule (.*)exp_packages\/\d+\/(.*)$ $1exp_packages/$2 [L,QSA] 
    # Pass all requests not referring directly to files in the filesystem to 
    # index.php. Clean URLs are handled in drupal_environment_initialize(). 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_URI} !=/favicon.ico 
    RewriteRule^index.php [L] 

    # Rules to correctly serve gzip compressed CSS and JS files. 
    # Requires both mod_rewrite and mod_headers to be enabled. 
    <IfModule mod_headers.c> 
    # Serve gzip compressed CSS files if they exist and the client accepts gzip. 
    RewriteCond %{HTTP:Accept-encoding} gzip 
    RewriteCond %{REQUEST_FILENAME}\.gz -s 
    RewriteRule ^(.*)\.css $1\.css\.gz [QSA] 

    # Serve gzip compressed JS files if they exist and the client accepts gzip. 
    RewriteCond %{HTTP:Accept-encoding} gzip 
    RewriteCond %{REQUEST_FILENAME}\.gz -s 
    RewriteRule ^(.*)\.js $1\.js\.gz [QSA] 

    # Serve correct content types, and prevent mod_deflate double gzip. 
    RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1] 
    RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1] 

    <FilesMatch "(\.js\.gz|\.css\.gz)$"> 
     # Serve correct encoding type. 
     Header set Content-Encoding gzip 
     # Force proxies to cache gzipped & non-gzipped css/js files separately. 
     Header append Vary Accept-Encoding 
    </FilesMatch> 
    </IfModule> 
</IfModule> 
+2

你可以显示'example.com'的'VirtualHost'条目吗?在这里添加完整的.htaccess。 – anubhava

+1

完成!谢谢 –

回答

1

添加此规则仅低于RewriteEngine On行:

# add a trailing slash to directories 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule [^/]$ %{REQUEST_URI}/ [L,NE,R=301] 

并重新测试在一个新的浏览器或完全清除浏览器缓存。

+0

这是一个很好的解决方案,但是这个网站比我所描述的解释情况复杂得多,在* all *的情况下添加一个斜线对我而言听起来有点可怕。只有在请求是专门针对http://example.com:8080/dir2的情况下,才可能添加此内容。 –

+0

不工作。它还在添加8080.( –

+0

)'dir2'还有一个.htaccess吗?在Chrome开发工具中测试禁用**缓存**并检入网络标签什么是您获得的301/302重定向网址。 – anubhava