我在Apache上使用重写规则疯了。 基本上我想实现的是重写任何url,如: http[s]://www.example.com/something 至 https://www.example.com 我在apache上有一个VHost,如下所示: <VirtualHost *:80> ServerName example.com ServerAlias example DocumentRoot /var/www/html/example_courtesy ServerAdmin [email protected] RedirectMatch 404 /\.git RedirectMatch 404 /\.svn <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/html/example_courtesy> Options Indexes FollowSymLinks MultiViews AllowOverride None Require all granted DirectoryIndex index.php indice.htm </Directory> RewriteEngine on RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] </VirtualHost> <IfModule […]
我的.htaccess文件中有以下代码: RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 上面的代码是为了将www添加到域,如果它没有www 。 但是我有一个域名: myloadbalancername-432566808.us-west-1.elb.amazonaws.com (来自AWS Elastic Load Balancer的DNS),并且该域名不能与www 。 那么,如何为所有的域请求添加www ,除了特定的域呢? RewriteCond %{REQUEST_URI} !myloadbalancername RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 我试着用上面的代码来检查域名是否有这个单词,然后检查域名是否没有www ,但没有成功。 我是.htaccess初学者,所以我不知道我做错了什么。
当在htaccess中设置我的redirect时,我无法设置/组合各个域名,当他们都去相同的主页。 我可以做他们分开,但不是整齐/优雅。 如何重写第三段它是如何工作的? RewriteCond %{REQUEST_URI} ^/$ RewriteCond %{HTTP_HOST} ^website.de$ // works fine RewriteRule ^$ de/home [R=301,L] RewriteCond %{HTTP_HOST} ^website.fr$ // works fine RewriteRule ^$ fr/home [R=301,L] RewriteCond %{HTTP_HOST} ^website.com$ // doesnt work well RewriteCond %{HTTP_HOST} ^website.org$ // doesnt work well RewriteCond %{HTTP_HOST} ^website.net$ // doesnt work well RewriteRule ^$ en/home [R=301,L]
我有一些这样的htaccess: RewriteCond %{HTTP_HOST} !^foo RewriteCond %{HTTP_HOST} !^bar RewriteCond %{HTTP_HOST} !^some RewriteRule ^register,(.*)$ /register.html [R=301,L] RewriteRule ^offer,(.*)$ /offer.html [R=301,L] 它redirect我,如果我写http://foo.domain.com/register,one.html我只想在http://domain.com/register,one.html或http://www.domain.com/注册,one.html 哪里不对?
我希望redirect(301)一个url,如果url不存在一个string。 例如: http :: //example.com必须总是redirect到http :: //example.com/en http :: //example.com/test.html必须总是redirect到http :: //example.com/en/test.html http :: //example.com/test/another_page必须始终redirect到http :: //example.com/en/test/another_page 喜欢这个。
在写rewritecond的时候,我想为各种IP提供子网。 那么我应该如何在下面的规则中给出子网掩码。 IP是218.104.51.160/29 RewriteCond %{HTTP:X-Forwarded-For} !^IP RewriteRule ^ – [F,L]
我有一个Web应用程序与多个页面。 .htaccess文件将domain-name.com/之后的所有内容redirect到我的index.php文件中,该文件处理input并呈现相应的页面。 但是,我也有一些实际的目录下domain-name.com/需要从redirect除外。 例如,我的PHPMyAdmin目录(/ pma)。 一切工作正常,直到我添加行redirect报告/ [名称]索引页也。 现在,我的/ pma不会进入PMA目录,而是进入我的应用程序的index.php。 如果我使用/pma/index.php,它可以工作,但是为什么/ pma会停止使用那个新的重写规则。 注释报告的RewriteRule导致一切再次运作。 我无法弄清楚为什么。 谢谢你的帮助! .htaccess文件: RewriteEngine On # Redirect http to https (http://htaccesscheatsheet.com/#force-https) RewriteCond %{HTTPS} !on RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} # Ignore the following directories (don't remap to page engine) RewriteCond %{REQUEST_URI} !^\/(pma*|css) #Redirect all /reports/[report name] requests to index.php?page=reports/[report name] RewriteRule ^reports/([a-z0-9\-_]+)\/{0,1}$ index.php?page=reports/$1 [NC,QSA,L] #Redirect […]
我有一堆域,我想要去一个域,但该域的各个部分。 # this is what I currently have RewriteEngine On RewriteCond %{HTTP_HOST} ^.*\.?foo\.com$ [NC] RewriteRule ^.*$ ${domainmappings:www.foo.com} [L,R=301] # rewrite map file www.foo.com www.domain.com/domain/foo.com.php www.bar.com www.domain.com/domain/bar.com.php www.baz.com www.domain.com/other/baz.php.foo 问题是我不想让每个域都成为RewriteCond的一部分。 我试过了 RewriteCond %{HTTP_HOST} ^www\.(.*) RewriteRule (.*) http://%1/$1 [R=301,L] 但是这将为每个域都这样做。 我只想要映射文件中的域redirect,然后继续进行其他重写,如果它不匹配映射文件中的任何域。
我在我的htaccess中写了一个规则,基本上这样说: 如果请求的是主页 而cookie尚未设置 用/addCookie.php重写页面 然后在addCookie.php中,我们设置cookie并redirect回主页。 这一切都很好,但如果用户不接受cookie,我们会得到一个无限循环的redirect。 我是新来的mod_rewrite,我做了很多search,但不能打破循环。 我到目前为止: RewriteCond %{ENV:REDIRECT_STATUS} 200 RewriteRule .* – [S=1] RewriteCond %{REQUEST_URI} "^/$" RewriteCond %{HTTP_COOKIE} !device_detected RewriteRule ^ addCookie.php [L] 我正在尝试做什么? 我可以添加一个查询string从addCookie.php的redirect,但我宁愿保持相同的请求。 任何build议,慷慨欢迎。
如果在主目录中不存在index.html或index.php文件,是否可以将(通过Rewrite Cond?)用户redirect到另一个URL以获得帮助? 感谢Greg