[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

.htaccess redirect

Posted on 2009-04-04
5
Medium Priority
?
215 Views
Last Modified: 2012-05-06
Ive tried different varitions of the following code and have failed to get it working correctly.

Basically if someone types in http://www.mydomain.com/gifts/Art.html

I want it to direct to http://www.mydomain.com/gallerytest.php?cid=Art


Im not getting any code errors just 'page not found'
Now Ive tested http://www.mydomain.com/gallerytest.php?cid=Art and it works so its definatly not redirecting correctly
RewriteCond %{HTTP_HOST} www.mydomain.com/gifts/([^/]+).html [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/gallerytest.php?cid=%1 [L]

Open in new window

0
Comment
Question by:misi_uk
[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
  • 2
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
cyberstalker earned 750 total points
ID: 24069485
The problem is twofold.

First of all you are comparing %{HTTP_HOST} to something that has a directory and a filename. The host is just that, the hostname.

Second, in the rewriterule, you don't use %1, but $1

Use this instead:
RewriteEngine On
 
RewriteCond %{HTTP_HOST} www.mydomain.com
RewriteRule ^gifts/(.*)\.html gallerytest.php?cid=$1

Open in new window

0
 

Author Comment

by:misi_uk
ID: 24070374
Thanks

thats still not working however.

That seem to look for the directory gifts so does not work.

Im new to .htaccess so Im out of my comfort zone with this. Ive tried so many variations and cant seem to get it working!
0
 
LVL 5

Assisted Solution

by:Pantalaim0n
Pantalaim0n earned 750 total points
ID: 24070657
It's always preferable to escape all special regex characters to minimize unexpected behaviour. It's also good to define a rewrite base. That, along with some other minor changes, try this:



RewriteEngine On
 
RewriteBase /  
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com [NC]
RewriteRule ^gifts\/(.*?)\.html gallerytest.php?cid=$1 [NC]

Open in new window

0
 
LVL 10

Expert Comment

by:cyberstalker
ID: 24070722
What do you mean with "it looks for a directory gifts so does not work'? This i got from your example.

Do you want all directories to be rewritten to gallerytest.php? Could you give me a few examples as to what URL's should be rewritten to what?
0
 

Author Comment

by:misi_uk
ID: 24070730
The rewrite base was already defined at the top of .htaccess

It didnt work however it was helpful and after some tweaking its now working thanks

I used the following in the end:
RewriteCond %{HTTP_HOST} ^www.mydomain.com
RewriteRule ^gifts\/(.*)\.html http://www.mydomain.com/gallerytest.php?cid=$1 [NC]

Open in new window

0

Featured Post

Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

Question has a verified solution.

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

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

650 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