Solved

Problems with CSS styles when using .htaccess and mod_rewrite

Posted on 2011-02-11
5
546 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility

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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
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). #…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

771 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

10 Experts available now in Live!

Get 1:1 Help Now