如何在apache上用mod_rewrite重写我的url?

时间:2022-09-17 16:52:22

I purchased a domain: josecvega.com

我购买了一个域名:josecvega.com

Whenever someone tries to access http://www.josecvega.com it forwards them to my web-server.

每当有人试图访问http://www.josecvega.com时,它都会将它们转发到我的网络服务器。

I have turned ON the mask, so when you initially reach my web-server of IP, 68.42.56.13, it still shows http://www.josecvega.com, but when you click on a link that takes you to another location on my web server, the http://www.josecvega.com disappears and turns into the IP address. I am currently trying to see if mod_rewrite can help solve this problem.

我已经打开了掩码,所以当你最初到达我的网络服务器IP,68.42.56.13时,它仍然会显示http://www.josecvega.com,但当你点击链接将你带到另一个位置时我的网络服务器,http://www.josecvega.com消失并变成IP地址。我目前正在尝试看看mod_rewrite是否可以帮助解决这个问题。

This is what I have so far in httpd.conf

这是我到目前为止在httpd.conf中所拥有的

RewriteEngine on
RewriteCond %{HTTP_HOST} =68.42.56.13

RewriteCond%{HTTP_HOST} = 68.42.56.13上的RewriteEngine

I am not sure how the rule would go to rewrite the URL.

我不确定该规则将如何重写URL。

Edit: My httpd.conf
I also understand that this issue is not strictly related to mod_rewrite, but I have tried fixing it in many different ways and non have seem to work, I was hoping that it could be done with mod_rewrite.

编辑:我的httpd.conf我也明白这个问题与mod_rewrite并没有严格的关系,但是我试过用很多不同的方法修复它并且似乎没有用,我希望可以用mod_rewrite完成。

2 个解决方案

#1


This is not related to the mod_rewrite.

这与mod_rewrite无关。

See ServerName and UseCanonicalName directive. Set them to your hostname and enable canonical name.

请参阅ServerName和UseCanonicalName指令。将它们设置为您的主机名并启用规范名称。

#2


Not sure mod_rewrite is relevant. You should configure your VirtualHost settings so that the ServerName is used.

不确定mod_rewrite是否相关。您应配置VirtualHost设置,以便使用ServerName。

For example:

NameVirtualHost *:80

<VirtualHost *:80>
ServerName josecvega.com
ServerAlias www.josecvega.com
DocumentRoot /var/www/vhosts/josecvega.com/htdocs
<Directory /var/www/vhosts/josecvega.com/htdocs>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>
</VirtualHost>

This assumes of course that you have access to httpd.conf which it appears you do. You can add a ton more directives to VirtualHost if you want, but by default it will use whatever the master httpd.conf has for all settings.

当然,这假定您可以访问httpd.conf,它就是您所看到的。如果需要,您可以向VirtualHost添加更多指令,但默认情况下,它将使用主httpd.conf对所有设置具有的任何指令。

Of course if you have only one website on your server anyway, you can just change the ServerName value in the main httpd.conf file.

当然,如果您的服务器上只有一个网站,您只需更改主httpd.conf文件中的ServerName值即可。

#1


This is not related to the mod_rewrite.

这与mod_rewrite无关。

See ServerName and UseCanonicalName directive. Set them to your hostname and enable canonical name.

请参阅ServerName和UseCanonicalName指令。将它们设置为您的主机名并启用规范名称。

#2


Not sure mod_rewrite is relevant. You should configure your VirtualHost settings so that the ServerName is used.

不确定mod_rewrite是否相关。您应配置VirtualHost设置,以便使用ServerName。

For example:

NameVirtualHost *:80

<VirtualHost *:80>
ServerName josecvega.com
ServerAlias www.josecvega.com
DocumentRoot /var/www/vhosts/josecvega.com/htdocs
<Directory /var/www/vhosts/josecvega.com/htdocs>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>
</VirtualHost>

This assumes of course that you have access to httpd.conf which it appears you do. You can add a ton more directives to VirtualHost if you want, but by default it will use whatever the master httpd.conf has for all settings.

当然,这假定您可以访问httpd.conf,它就是您所看到的。如果需要,您可以向VirtualHost添加更多指令,但默认情况下,它将使用主httpd.conf对所有设置具有的任何指令。

Of course if you have only one website on your server anyway, you can just change the ServerName value in the main httpd.conf file.

当然,如果您的服务器上只有一个网站,您只需更改主httpd.conf文件中的ServerName值即可。