dongpi2503 2019-02-23 09:36
浏览 71

如何将子文件夹别名或重写为域

I have a folder structure like this

/
/project1

I normally use it with one domain (example.com), but now I want to use it as a sepreate domain (project1.example.com) and I am using apache virtualhost. I have succeed to setup, but some problem on the link happened. All the hyperlink in project1 is the path included the "project1" subfolder (e.g. project1/image/pic.jpg). I setup like this

DocumentRoot /doc_root/
Alias /project1 /doc_root/project1/
Alias / /doc_root/project1

RewriteRule /project1/(.*) /$1 [R]

The problem is when i rewrite clean url e.g. example.com/project1/post?id=1 => project1.example.com/post/1 With

RewriteRule ^/post/(\d+)$ /project1/post.php?id=$1 [PT,NC,L,QSA]

I am getting 404 error in the ajax post in the page Since the ajax url is pointed to /project1/process.php And I think this request is not rewriting.

What is the proper way to setup like this? thanks!

  • 写回答

1条回答 默认 最新

  • dongxiezhi9564 2019-02-24 18:36
    关注

    There's several issues here:

    1. The Alias rules don't look correct and are confusing.
    2. The redirect rule you provided won't extract a query string parameter (i.e. it won't rewrite the path from /project1/post?id=1 to /post/1) nor does it alter the domain name (i.e. it won't change the domain to project1.example.com).
    3. There's no need for the redirect.

    I think what you want is something like:

    DocumentRoot /doc_root/
    
    RewriteCond %{HTTP_HOST} ^project1\.example\.com$
    RewriteRule ^/(.*)$ /project1/$1 [NC,PT]
    

    If you do actually want to redirect, consider:

    RewriteCond %{HTTP_HOST} ^example\.com$
    RewriteRule ^/project1/(.*)$ project1.example.com/$1 [NC,R]
    
    评论

报告相同问题?

悬赏问题

  • ¥15 对于知识的学以致用的解释
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败