Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mod_rewrite VS relative paths

My mod_rewrite code is:

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)?$ index.php?url=$1 [L,NC]

This structure is placed on my server path /beta

When I place the URL http://mydomain.com/beta/download everything works rewriting to the real path http://mydomain.com/beta/index.php?url=download

The problem happens with the relative paths. When I enter the URL http://mydomain.com/beta/download/box the rewriting goes to http://mydomain.com/beta/index.php?url=download/box... but....

All my relative paths, like my css folder, my js folder, image files.... everything with relative path in my index.php page crashes, cuz my relative paths become download/css, download/js, download/images... etc...

I know this problem happens in reason of the slash in the path "download/", but how can I solve that using the mod_rewrite in .htaccess?

Can I prevent rewriting in relative paths? Or even in internal paths of my own domain?

How can I solve that WITHOUT change my relative paths to absolute paths?

Thanks

like image 364
user464230 Avatar asked Jun 13 '11 17:06

user464230


People also ask

What is RewriteCond and RewriteRule?

There are two main directive of this module: RewriteCond & RewriteRule . RewriteRule is used to rewrite the url as the name signifies if all the conditions defined in RewriteCond are matching. One or more RewriteCond can precede a RewriteRule directive.

What is mod_ rewrite?

The term "mod_rewrite" refers to a module for the Apache web server, which “rewrites” or redirects requests to specified content. Basically, the module transforms incoming requests to a path in the web server's file system. This makes it possible to "rewrite" a URL.

What is Apache Rewrite engine?

A rewrite engine is a component of web server software that allows you to rewrite or redirect uniform resource locators (URLs). The most popular rewrite engine is the Apache HTTP server's mod_rewrite. There are other web servers, such as nginx or lighttpd, that provide similar functions.


1 Answers

Add a <base href="yoururl.com/beta/"; /> tag to your HTML head. Also add RewriteBase /beta/ to the htaccess if you're in that subfolder

like image 87
Joshua - Pendo Avatar answered Oct 20 '22 00:10

Joshua - Pendo