Solved

Problems with CSS styles when using .htaccess and mod_rewrite

Posted on 2011-02-11
5
547 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
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 theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
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.

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now