How to define a fixed URL

New to mod_rewrite? This is a good place to start.

How to define a fixed URL

Postby GertvdBrink » Sat Jun 20, 2009 12:22 pm

Hello anyone who is reading this,

I'm new on this forum, I found it looking for some information about mod_rewrite.

I'm a webdesigner and I developed my own CMS to provide some extra service to my clients.

I'm working with some simple mod_rewrite code for SEO.

For example:
Code: Select all
RewriteEngine On
RewriteBase /
RewriteRule ^beheer/$ beheer/index.php [L]
RewriteRule ^artikel/(.*)/$ artikel.php?id=$1 [L]
RewriteRule ^(.*)/$ index.php?webnaam=$1 [L]
RewriteRule ^beheer$ beheer/index.php [L]

As you can see, the links of my page's would look like this:
Code: Select all
http://www.mywebpage.com/homepage/

But, a lot of time I'm testing things on my own domain on a subdirectory, or at my localhost at a subdirectory, so then te links look like:
Code: Select all
http://localhost/subdirectory/homepage/

So verytime I put a website from my website/localhost to the real domain I have to change al the links/css reference's/javascript links/etc... and that's a lot of work and sometimes I forget one and than it don't work at the right way.

So my question is, could I make something link a substitute for de domain in a .htacces, so that I only have to change de url there and it automatic change everywhere else?
The idea is making my links something like:
Code: Select all
{URL}/home/
{URL}/style.css
{URL}/javascript.js

And that .htacces change's that {URL} to the actual URL to the website. So that if I changes from domain / or directory I only have to change that regerence in the .htacces?

Is this possible?

Sorry for my poor English...

Thanks a lot for anyone who tries to help me! :wink:

Best regards

Gert van den Brink
GertvdBrink
 
Posts: 1
Joined: Sat Jun 20, 2009 1:01 am

Postby richardk » Sun Jun 21, 2009 9:52 am

You might be able to use relative paths (relative to the URL not the file).

Or you could use the HTML <base> element or a PHP constant/variable. FAQ: Relative paths to images, JavaScript, CSS and other external/linked files are broken.

Or you could set up <VirtualHost>s on your local server so you could have a (fake) domain name go to a different directory so you could have fake.tld/homepage/ instead of localhost/subdirectory/homepage/.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 106 guests

cron