如何自定义单词添加到我的域名网址为每个请求?(How to add a custom word to

2019-07-31 13:51发布

考虑我的域名

www.mydomain.com

考虑一个页面请求

www.mydomain.com/user/register

我想补充的基础URL后自定义字内mydomain.com.example每个请求

www.mydomain.com/customword/
www.mydomain.com/customword/user/register

我们能做到这一点使用URL在htaccess的文件重写?

其实这应该执行“www.mydomain.com/user/register”内部...但外部的URL看起来应该像www.mydomain.com/customword/user/register。

Answer 1:

You could create the directory "register", and put an index file inside it that performs the action.

That's probably the simplest way without url rewriting anyway.


UPDATE (since the question was updated)

In .htaccess:

RewriteEngine On
RewriteRule ^([A-Za-z0-9-.]+)/user/register/?$ user/register.php?customword=$1

register.php will receive a GET request:

//User went to www.mydomain/word/user/register
echo $_GET['customword']; // will return word in this case

Make sure that you have mod_rewrite enabled :)



Answer 2:

是的,你可以用htaccess的做到这一点

下面是这将增加一个尾随斜线与URL如果它不包含尾随斜线的例子

http://enarion.net/web/htaccess/trailing-slash/



Answer 3:

编辑格式更新
如果您是从本服务一个网站,然后下面应该工作:

编辑您.htaccess文件做一个URL重写

访问www.yourdomain.com/user/registry实际上会从服务器的内容www.yourdomain.com/customword/user/registry

RewriteEngine On<br>
RewriteCond %{REQUEST_URI} !^/customword/<br>
RewriteRule ^(.*)$ /customword/$1

您还没有提到什么样的网站,你的;再using..eg:PHP,MVC等,你可以做类似的事情在那里。



文章来源: How to add a custom word to my domain URL for every request?