Solved

Problems with CSS styles when using .htaccess and mod_rewrite

Posted on 2011-02-11
5
550 Views
Last Modified: 2012-05-11
I am using .htaccess fand mod_rewrite to redirect pages. Basically I would like to do the following:

The link http://www.mydomain.com/movie should be redirected to:

 http://www.mydomain.com/topic.php?p=movie

I am using the following:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9\-\_\ \%]*)$ /topic.php?p=$1&%{QUERY_STRING}

When I introduce something like http://www.mydomain.com/movie/movie the link is redirected but all the styles and css files are missing.

I mean, if I introduced more than one "/" the redirect is not working properly.

Any idea?

Thanks
0
Comment
Question by:voteg
  • 3
  • 2
5 Comments
 
LVL 8

Assisted Solution

by:rationalboss
rationalboss earned 500 total points
ID: 34877041
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9\-\_\ \%]*)(/){0,1}$ /topic.php?p=$1&%{QUERY_STRING}
0
 

Author Comment

by:voteg
ID: 34877316
I tryed and still does not work.

The images and css styles are still missing.

Any other suggestion?
0
 
LVL 8

Accepted Solution

by:
rationalboss earned 500 total points
ID: 34877339
I'm sorry I did not get it the first time.

In your template where you put the <link> tags. Use absolute paths:
<link href="http://mysite.com/style/style.css" rel="stylesheet" type="text/css" />

-or-
<link href="/style/style.css" rel="stylesheet" type="text/css" />
0
 

Author Comment

by:voteg
ID: 34877423

It works in the server, but affects all my css files in my local server.

I mean,  if I use <link href="/style/style.css" rel="stylesheet" type="text/css" />my local css does not work. What can I do? I have tryed several things but did not work.

Thanks
0
 
LVL 8

Assisted Solution

by:rationalboss
rationalboss earned 500 total points
ID: 34877443
If you have a configuration file, you can do this:

<?php
if ($_SERVER['HTTP_HOST'] == 'localhost') DEFINE('SITE_LINK','http://localhost/mywebsite/');
else DEFINE('SITE_LINK','http://www.mydomain.com/');
?>

in your template page, just use:
<link href="<?php echo SITE_LINK; ?>style/style.css" rel="stylesheet" type="text/css" />
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
My project did see openJDK that I installed. What could be the problem 7 161
word0 challenge 4 72
firstChar challenge 13 132
Link failure 16 63
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
This video teaches viewers about errors in exception handling.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question