考虑我的域名是
www.mydomain.com
考虑一个页面请求
Consider a page request
www.mydomain.com/user/register
我要添加基本URL的自定义字内mydomain.com.example每个请求
I want to add a custom word after base URL for every request inside mydomain.com.example
www.mydomain.com/customword/
www.mydomain.com/customword/user/register
我们能做到这一点使用URL htaccess的文件重写?
Can we do this using URL rewriting in htaccess file ?
其实这应该执行www.mydomain.com/user/register内......但外部的URL看起来应该像www.mydomain.com/customword/user/register。
Actually it should execute 'www.mydomain.com/user/register' internally...but externally the URL should look like www.mydomain.com/customword/user/register.
您可以创建注册,该目录,并把索引文件里面执行的操作。
You could create the directory "register", and put an index file inside it that performs the action.
这可能是不反正URL重写最简单的方法。
That's probably the simplest way without url rewriting anyway.
在.htaccess:
In .htaccess:
RewriteEngine On
RewriteRule ^([A-Za-z0-9-.]+)/user/register/?$ user/register.php?customword=$1
register.php将收到一个GET请求:
register.php will receive a GET request:
//User went to www.mydomain/word/user/register
echo $_GET['customword']; // will return word in this case
请确保您有mod_rewrite的启用了:)
Make sure that you have mod_rewrite enabled :)