I am moving to a new host that does not allow access to edit httpd.conf or vhosts.conf, so I need to use .htaccess instead.
Here's my existing virtual host 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>
The goal is to get the same interaction using htaccess.
The primary interaction I'm looking for is:
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/
The above vhosts.conf works just fine on my old host, but I'm unsure how to execute this on my new host with only htaccess.
Turns out my specific issue was with a hosting configuration instead of a mod_rewrite problem. But for others, here's my solution:
/path/to/html/.htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.