Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mod_rewrite and relative urls

I'm setting up some simple url rewriting rules using mod_rewrite and a .htacces file, but I've got some problems. If I set up the .htacces this way:

Options +FollowSymLinks

RewriteEngine On
RewriteBase /

RewriteRule /index.html /index.php [L]

when I call from the browser this url: http://localhost/~dave/mySite/index.html I got a 404 error.

Using this .htacces instead

Options +FollowSymLinks

RewriteEngine On
RewriteBase /

RewriteRule /index.html http://localhost/~dave/mySite/index.php [L]

everything works fine and I get the index.php page I'm expecting. Am I forced to user absolute urls as the target of a rewrite? Is this a Apache configuration problem?

I'm using Max OS X 10.6.2 with its standard Apache installation.

like image 509
Davide Gualano Avatar asked Jan 21 '26 18:01

Davide Gualano


1 Answers

  1. The RewriteBase base directive is setting a base path; you don't need to provide absolute paths in the redirection rules.

  2. The rule pattern is not plain text; it's a regular expression.

  3. If you set a full URL as target you instruct the browser to redirect to that other location; that kind of redirection is not transparent to the user.

To sum up, try this instead:

RewriteRule ^index\.html$ index.php [L]
like image 105
Álvaro González Avatar answered Jan 23 '26 20:01

Álvaro González



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!