htaccess的子站点和URL重写重写、站点、htaccess、URL

2023-09-02 09:51:31 作者:仅有的、单纯,你也要霸占

我就麻烦了这个的.htaccess

 的RewriteCond%{HTTP_HOST} appname.domain.com
的RewriteCond%{REQUEST_URI}!应用程序的名字/
重写规则^(。*)$ /应用程序的名字/ $ 1 [L]
 

在文档根目录(不是真正的根文件,比方说一个V-domain文件夹),我有这个文件夹,名为应用程序名称。在appname.domain.com样样精显示为它应该。现在我的问题是,当我想要做这样的事情

  http://appname.domain.com/somefolder
 

我不希望URL重写到     appname.domain.com/appname/somefolder 在地址栏。 任何帮助?

更新: 在文档根目录,我有

 的RewriteCond%{HTTP_HOST}!^ WWW 。域 .COM $ [NC]
的RewriteCond%{HTTP_HOST} ^(。*)。域 .COM $ [NC]
的RewriteCond%{REQUEST_URI}!^ V-域/
重写规则^(。*)$ / v-结构域/ $ 1 [L]
 
.htaccess伪静态规则转换为IIS的URL重写规则方法

在V-域

  RewriteEngine叙述上
的RewriteBase / v-结构域/

的RewriteCond%{HTTP_HOST} appname.domain.com
的RewriteCond%{REQUEST_URI}!应用程序的名字/
重写规则^(。*)$ /应用程序的名字/ $ 1 [L]
的RewriteCond%{HTTP_HOST} appname.domain.com
的RewriteCond%{} REQUEST_FILENAME -d
的RewriteCond%{REQUEST_URI}!/ $
重写规则^应用程序的名字/(.+)$ http://appname.domain.com/$1/ [R = 301,L]
###################
的RewriteCond%{HTTP_HOST} appname2.domain.com
的RewriteCond%{REQUEST_URI}!appname2 /
重写规则^(。*)$ / appname2 / $ 1 [L]
的RewriteCond%{HTTP_HOST} appname2.domain.com
的RewriteCond%{} REQUEST_FILENAME -d
的RewriteCond%{REQUEST_URI}!/ $
重写规则^ appname2 /(.+)$ http://appname2.domain.com/$1/ [R = 301,L]
 

解决方案   

尽量让你的子域文件夹目录,在它的索引,然后努力达成这条道路。您将看到URL被改写的丑陋上述办法appname.domain.com/appname/somefolder

这听起来像它的 mod_dir的DirectorySlash 的interferring。随着DirectorySlash开启,如果mod_dir看到一个请求是由一个目录中,缺少结尾的斜线,它的重定向浏览器相当于网址后面的斜线。

有些东西你可以做的是把 DirectorySlash关闭但有一个公开的关注,当谈到DirectoryIndex'ing(见mod_dir的DirectorySlash项)。你可以尝试加入一些规则来做到这一点重定向你,但要确保没有在URL中 /应用程序的名字/ 位重定向:

 的RewriteCond%{HTTP_HOST} appname.domain.com
的RewriteCond%{} REQUEST_FILENAME -d
的RewriteCond%{REQUEST_URI}!/ $
重写规则^应用程序的名字/(.+)$ http://appname.domain.com/$1/ [R = 301,L]
 

这基本上是检查,如果请求的是主机 appname.domain.com ,所请求的实体是一个目录,该请求不不结束以斜线,如果该请求已经被改写为 /应用程序的名字/ 将浏览器重定向到相同的URL(没有应用程序的名字),但斜线。重定向后,你必须将在内部重写URI的第一个规则,以包括/应用程序的名字/,但由于要求现在斜线结束,mod_dir应该忽略它。

I'm in trouble with this .htaccess

RewriteCond %{HTTP_HOST} appname.domain.com
RewriteCond %{REQUEST_URI} !appname/
RewriteRule ^(.*)$ /appname/$1 [L]

In the document root (not really the root document, let's say a v-domain folder) i have this folder called 'appname'. On appname.domain.com everything shows up fine as it should. Now my problem is when I want to do something like this

http://appname.domain.com/somefolder

I don't want the url to be rewritten to appname.domain.com/appname/somefolder In the url bar. Any help?

Update: In the document root i have

RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*).domain.com$ [NC]
RewriteCond %{REQUEST_URI} !^v-domain/
RewriteRule ^(.*)$  /v-domain/$1 [L]

In v-domain

RewriteEngine On
RewriteBase /v-domain/

RewriteCond %{HTTP_HOST} appname.domain.com
RewriteCond %{REQUEST_URI} !appname/
RewriteRule ^(.*)$ /appname/$1 [L]
RewriteCond %{HTTP_HOST} appname.domain.com
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^appname/(.+)$ http://appname.domain.com/$1/    [R=301,L]
###################
RewriteCond %{HTTP_HOST} appname2.domain.com
RewriteCond %{REQUEST_URI} !appname2/
RewriteRule ^(.*)$ /appname2/$1 [L]
RewriteCond %{HTTP_HOST} appname2.domain.com
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^appname2/(.+)$ http://appname2.domain.com/$1/  [R=301,L]

解决方案

Try to make a dir in your subdomain folder with an index in it and then try to reach that path. You will see the url being rewritten in the ugly mentioned way "appname.domain.com/appname/somefolder"

That sounds like it's mod_dir's DirectorySlash interferring. With DirectorySlash turned on, if mod_dir sees that a request is made for a directory and is missing the trailing slash, it redirects the browser to the equivalent URL to include the trailing slash.

Something you can do is to turn DirectorySlash off but there's a disclosure concern when it comes to DirectoryIndex'ing (see the DirectorySlash entry in mod_dir). You could try adding some rules to do this redirect for you but make sure to redirect without the /appname/ bit in the URL:

RewriteCond %{HTTP_HOST} appname.domain.com
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^appname/(.+)$ http://appname.domain.com/$1/    [R=301,L]

This basically checks if the request is for the host appname.domain.com, that the requested entity is a directory, that the request does not end with a trailing slash, and if the request has already been rewritten for /appname/ redirect the browser to the same URL (without appname) but with a trailing slash. After the redirect, the first rule that you have will internally rewrite the URI to include the /appname/, but since the request now ends with a trailing slash, mod_dir should ignore it.