Solved

Problems with CSS styles when using .htaccess and mod_rewrite

Posted on 2011-02-11
5
551 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
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.

710 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