子域名重定向使用htaccess的 [英] Sub-domain Redirect Using htaccess

查看:153
本文介绍了子域名重定向使用htaccess的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作,需要重写URL如

一个项目
  

https://orange.url.com

  

https://www.url.com/?s=orange

我需要如何生产出htaccess的来处理这个任务的帮助。 PS:请注意,我已经有以下我的htaccess处理一些改写为我

  RewriteEngine叙述上
的RewriteBase /

#要外部重定向/dir/foo.php到/ DIR /富
的RewriteCond%{THE_REQUEST} ^ [AZ] {3,} \ S([^。] +)\。PHP [NC]
重写规则^%1 / [R,L]

#添加斜线
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_FILENAME} \ PHP -f
的RewriteCond%{REQUEST_URI}!/ $
重写规则。 %{REQUEST_URI} / [R,L]

#在内部前进/ DIR /富到/dir/foo.php
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_FILENAME} \ PHP -f
重写规则^(。*?)/?$ $ 1.PHP [L]
 

解决方案

您可以把这个code在你的htaccess的(这必须是在你的根文件夹中)

 选项-MultiViews

RewriteEngine叙述上
的RewriteBase /

#在内部推进http://xxx.domain.com到http://www.domain.com/?s=xxx
的RewriteCond%{HTTP_HOST} ^((?!万维网\)。+?)\。例如\ .COM $ [NC]
重写规则^ $的index.php?S =%1 [L]

#在内部推进http://xxx.domain.com/yyy/到http://www.domain.com/?s=xxx&c=yyy
的RewriteCond%{HTTP_HOST} ^((?!万维网\)。+?)\。例如\ .COM $ [NC]
重写规则^([^ /] +)/ $的index.php S =%1安培; C = $ 1 [L]

#在内部推进http://xxx.domain.com/yyy/zzz/到http://www.domain.com/?s=xxx&c=yyy&g=zzz
的RewriteCond%{HTTP_HOST} ^((?!万维网\)。+?)\。例如\ .COM $ [NC]
重写规则^([^ /] +)/([^ /] +)/ $ index.php的S =%1和; C = $ 1和克= $ 2 [L]

#要外部重定向/dir/foo.php到/ DIR /富/
的RewriteCond%{THE_REQUEST} \ S /(。+?)\ PHP [NC]
重写规则^%1 / [R,L]

#添加斜线
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI}!/ $
重写规则^(。*)$ $ 1 / [R,L]

#在内部前进/ DIR /富/到/dir/foo.php
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{DOCUMENT_ROOT} / $ 1 \ .PHP -f
重写规则^(。+?)/ $ $ 1.PHP [L]
 

I am working on a project that requires rewriting a URL like

https://orange.url.com

to

https://www.url.com/?s=orange

I need assistance on how to churn out htaccess to handle this task. PS: Please not that I already have the following in my htaccess handling some rewriting for me.

RewriteEngine On
RewriteBase /

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R,L]

# add a trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule . %{REQUEST_URI}/ [R,L]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

解决方案

You can put this code in your htaccess (which has to be in your root folder)

Options -MultiViews

RewriteEngine On
RewriteBase /

# To internally forward http://xxx.domain.com to http://www.domain.com/?s=xxx
RewriteCond %{HTTP_HOST} ^((?!www\.).+?)\.example\.com$ [NC]
RewriteRule ^$ index.php?s=%1 [L]

# To internally forward http://xxx.domain.com/yyy/ to http://www.domain.com/?s=xxx&c=yyy
RewriteCond %{HTTP_HOST} ^((?!www\.).+?)\.example\.com$ [NC]
RewriteRule ^([^/]+)/$ index.php?s=%1&c=$1 [L]

# To internally forward http://xxx.domain.com/yyy/zzz/ to http://www.domain.com/?s=xxx&c=yyy&g=zzz
RewriteCond %{HTTP_HOST} ^((?!www\.).+?)\.example\.com$ [NC]
RewriteRule ^([^/]+)/([^/]+)/$ index.php?s=%1&c=$1&g=$2 [L]

# To externally redirect /dir/foo.php to /dir/foo/
RewriteCond %{THE_REQUEST} \s/(.+?)\.php [NC]
RewriteRule ^ %1/ [R,L]

# add a trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1/ [R,L]

# To internally forward /dir/foo/ to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^(.+?)/$ $1.php [L]

这篇关于子域名重定向使用htaccess的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆