0
我正在轉移到一個不允許編輯httpd.conf或vhosts.conf的新主機,因此我需要使用.htaccess。如何在httpd.conf中將我的虛擬主機modrewrite轉換爲使用.htaccess?
這裏是我現有的虛擬主機的conf:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.dev
DocumentRoot /path/to/html
Alias /sitemap.xml /path/to/html/sitemap.php
Alias /sitemap.xml.gz /path/to/html/sitemap.php
AliasMatch ^/sitemap(.*).xml /path/to/html/sitemap.php
AliasMatch ^/sitemap(.*).xml.gz /path/to/html/sitemap.php
Alias /robots.txt /path/to/html/robots.php
AliasMatch ^/robots.txt /path/to/html/robots.php
<Directory /path/to/html>
AllowOverride none
Options all
Order allow,deny
Allow from all
Deny from none
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
# The following redirects all directories to root using PATH variables
# Ex. /abc/def/ redirects to /index.php/abc/def/
RewriteCond %{REQUEST_URI} !=/server-status
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php/$1 [L]
</IfModule>
</Directory>
</VirtualHost>
的目標是使用的htaccess得到相同的作用。
我在尋找的主要交互是:
sitemap.xml => sitemap.php
sitemap-abc.xml => sitemap.php
sitemap-___.xml => sitemap.php
sitemap-xyz.xml => sitemap.php
robots.txt => robots.php
/abc/def/ => /index.php/abc/def/
以上vhosts.conf作品在我的舊主機上就好了,但我不知道該如何我只htaccess的新主機上執行該。
嗯...是要定義裏面.htaccess文件虛擬主機?如果甚至沒有定義主機,服務器應該如何知道它打算掃描包含.htaccess文件的文件夾? – arkascha
你是說使用htaccess而不是虛擬主機使用這些模式modrewrite是不可能的? – Ryan
對不起,好像我誤解了你的目標......是的,當然你也可以在'.htaccess'文件中進行大部分的重寫和重定向。這只是第二選擇,在少數情況下會更復雜,但是你沒有其他選擇。但是我沒有看到你的實際問題是什麼:所需的重寫規則顯得非常直截了當,正如優秀文檔mod_rewrite中給出的示例一樣。你究竟在哪裏碰到問題? – arkascha