I need to a redirect rule that, as an example, takes www.domain.com and redirects it to www.topic.com/page.php?Topic=10 I still need to keep the URL as www.domain.com though. Does anyone know a Rewrite rule to do this?
g1smd
9:21 am on Jun 10, 2010 (gmt 0)
You'll need a rewrite not a redirect. The code could use
RewriteRule
for sure.
There's more than twenty thousand code examples of rewrites in this forum.
What have you tried so far?
Another way to do this might be to use the
DirectoryIndex
directive.
Let's see your code.
DaminAssad
9:53 am on Jun 10, 2010 (gmt 0)
Here's what I've been working with:
RewriteEngine on RewriteCond %{HTTP_HOST} ^www.domain.com RewriteRule ^/(.*)$ /page.php?Topic [L]
I keep getting "Page cannot be displayed" though...
jdMorgan
4:26 pm on Jun 10, 2010 (gmt 0)
That's likely because "Topic" has no equal sign or "topic-name" following it.
Really, you have to define what you want to do more thoroughly if anyone here is to contribute anything useful...
How many 'topics' do you have?
How are 'topic numbers' related to the client-requested URL-path? (In your only example above, script query "Topic=10" is associated with "URL-path is blank." That's a single data point, from which it is impossible to deduce what URL-paths any other topic numbers might be associated with.)
Coding is relatively easy -- but only after the requirements are fully-specified.
Jim
[edited by: jdMorgan at 2:11 pm (utc) on Jun 11, 2010]
DaminAssad
7:52 am on Jun 11, 2010 (gmt 0)
Yeah sorry, i left some characters out when copying. this is what i have
RewriteEngine on RewriteCond %{HTTP_HOST} ^www.domain.com RewriteRule ^/(.*)$ /page.php?Topic=10 [L]
The rewrite is only for this one topic, i won't be needing to do it for all the topics.
jdMorgan
2:22 pm on Jun 11, 2010 (gmt 0)
This code won't work in .htaccess or in a server config file within a <Directory /> container, because the RewriteRule won't 'see' a leading slash. The URL-paths examined by RewriteRule are 'localized' to the <Direcotry />-specified location or to the .htaccess file's location.
So for use in .htaccess, the first thing to do is to remove the leading slash from the RewriteRule's pattern.
The rule will then rewrite *all* requests sent to this server to the /page.php?Topic=10 filepath, including requests for images, robots.txt, and even page.php itself (this latter creating an infinite rewrite loop).
Is that what you want?
Your code and your example are mutually-inconsistent, so again, it's difficult to work with incomplete requirements.
Perhaps you're looking to rewrite only requests for the "home page" at "www.example.com/" which would make the code:
RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.domain\.com RewriteRule ^$ /page.php?Topic=10 [L]
And note that if you have no other subdomains in addition to "www" then the RewriteCond is not needed.