This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
.htaccess redirect
How exactly, with a .htaccess file i'm presuming, would i redirect people from this URL: http://blog.twostepmedia.co.uk/win-traffic-with-charlie-sheen-and-the-yahoo-boss-api/ to something like http://www.twostepmedia.co.uk/blog/win-traffic-with-charlie-sheen-and-the-yahoo-boss-api/
Thanks :)
You're better off using a rewrite rule in your .htaccess of the blog.twostepmedia.co.uk domain.
Something like
RewriteEngine on
RewriteOptions MaxRedirects=10 # this will just stop and bugs in the code causing a infinite loop
RewriteRule ^(.+)$ http://www.twostopmedia.co.uk/blog/$1 [R=301,NC]
The rewrite rule grabs whatever follows 'blog.twostepmedia.co.uk/' and rewrites to the new url. The [R=301,NC] sets this to be a permanent redirect, which means you won't get penalised from duplicate content by search engine spiders.
Hope that helps :)
Related
This question already has answers here:
Remove .php extension with .htaccess
(17 answers)
Closed 4 years ago.
My URLs look like this:
mywebsite.com/subpage-name.php
I want my new links to look like this:
mywebsite.com/subpage-name/
How can I redirect all my ".php" pages to "/" pages?
You have to add a RewriteRule in your .htaccess with a regex.
RewriteRule ^(.*)$ http://www.thenewdomain.com/$1 [R=permanent,L]
Make sure to add
RewriteEngine on
Before applying the redirect rule.
Happy Coding.
I know there are already a ton of these questions but I don't get it...
I'm trying to rewrite my /register.php to /register but I can't.
.htaccess code
RewriteEngine on
RewriteBase /
RewriteRule ^register$ register.php [L]
Does any of you know the answer?
Sorry for the stupid question but I'm kinda new to the whole .htaccess stuff...
Do you have enabled the Apache module mod_rewrite?
I use this pattern to create user-friendly URLs. It's pretty variable. It means, that every address in format letters-numbers with a certain file extension (PHP or HTML) will be translate into letters-numbers.php (for example).
RewriteRule ^([a-z]+)-([0-9]+)\.(php|html)$ /$1-$2.$3 [L]
Please look at the edits on this post. The last code examples I give are what I'm trying to accomplish. I have 147 lines of code that I'm working with. I guess I'm actually not trying to make a rule so much as I am trying to figure out redirects with those variables.
OK, I've been researching this for a few hours, and the regex apache rewrite rules get pretty specific and I'm stumped. Client has asked that the old site urls be rewritten/redirected to the new drupal site and corresponding pages that have url aliases. There are 147 variables (all 1 - 216 (out of sequence))
Example:
I need
/hardware/bikes.php?recordID=1 to redirect to http://www.bikerus.com/?q=hardware/first-bike-that-really-flies
then
/hardware/bikes.php?recordID=2 to redirect to http://www.bikerus.com/?q=hardware/second-awesome-bike-that-really-flies
and so on
This is what I have so far:
RewriteCond %{QUERY_STRING} ^recordID=([0-9]+)$
RewriteRule ^/hardware/bikes\.php?recordID=%1$ http://www.bikerus.com/?q=hardware/first-bike-that-really-flies
This is obviously not working, any ideas ladies and chaps?
Ideally, it would be great if I could figure out another problem with Drupal I haven't figured out yet (for years).
Have a redirect that goes like this:
redirect 301 /hardware/1.html http://www.bikerus.com/hardware/first-bike-that-really-flies
Instead of this:
redirect 301 /hardware/1.html http://www.bikerus.com/?q=hardware/first-bike-that-really-flies
But my first question is the priority now.
Thanks in advance.
EDITS:
The files I'm trying to redirect to aren't static, they're url aliases generated by Drupal's database.
In the end, yes, I will need to make 147 individual records (hardcoded), my question is how to do this:
redirect 301 /hardware/bikes.php?recordID=1 http://www.bikesrus.com/?q=hardware/random-bike-title-one
redirect 301 /hardware/bikes.php?recordID=2 http://www.bikesrus.com/?q=hardware/random-bike-title-two-ewhbcfn
redirect 301 /hardware/bikes.php?recordID=3 http://www.bikesrus.com/?q=hardware/random-bike-title-three-kxjhmuflr
redirect 301 /hardware/bikes.php?recordID=4 http://www.bikesrus.com/?q=hardware/random-bike-title-four-more-random-stuff
And for those that don't know, Drupal has a clean url rewrite rule that comes shipped with the .htaccess file that I'm currently editing:
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
So I need to be able to navigate this as well.
The problem to your second issue is that redirect really stinks for anything past a simple redirect. You need a RewriteRule to make this:
redirect 301 /hardware/1.html http://www.bikerus.com/?q=hardware/first-bike-that-really-flies
More like this:
RewriteRule ^([a-zA-Z]+)/$ /?q=$1 [R=301,L]
Or maybe this:
RewriteRule ^([a-zA-Z]+)/(.*)$ /?q=$1/$2 [R=301,L]
But it’s not clear in your post where you are getting the first-bike-that-really-flies stuff from. So not to clear on how to handle that in Drupal. Very specific to your setup.
Actually just answered a mod_rewrite question similar to this over here. Might give you more insight.
Just figured it out.
RewriteCond %{THE_REQUEST} recordID=1
RewriteRule . http://www.bikesrus.com/hardware/bike-that-really-flies? [R=301,L]
BOTH!! On my own, with a little more searching. The difference is that I put the word "hardcoded" into my search keywords this time. Thanks everyone who commented.
Please help me to redirect using .htaccess like below.
http://info.domainname.com/blog/?Tag=somedynamictag
to
http://domainname.com/tag/somedynamictag
Thanks!
First of all I don't understand the purpose of rewriting http://info.domainname.com/blog/?Tag=somedynamictag to http://domainname.com/tag/somedynamictag when it had to be the other way round. People rewrite URLs to clean them (ie. remove characters like ?,&,=, etc.) but you are adding all these and making the URLs cumbersome.
I think you didn't properly understand the concept of URL rewriting. Let me explain a little.
When any URL is accessed on your website, the URL that the USER types or clicks (in your case http://domainname.com/tag/somedynamictag) is rewritten. But your question tells me that you think the other way. Your understanding is that the visitor clicks http://info.domainname.com/blog/?Tag=somedynamictag and will be rewritten to http://domainname.com/tag/somedynamictag. THIS IS WRONG!!. If you set up your website this way, each and every URL at http://domain.com/ must exist as a separate file or directory which a dynamic website like you seem to be developing is not expected to have. So I assume you have understood that you have either misformed the question or you have you have misunderstood the concept of URL rewriting. Following is the .htaccess code to redirect http://domainname.com/tag/somedynamictag to http://info.domainname.com/blog/?Tag=somedynamictag.
RewriteEngine On
RewriteCond %{HTTP_HOST} domainname.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9]+)\/(.*)$ http://info.domainname.com/blog/?$1=$2 [L,R=301]
If you think you have correctly typed the question and understood url-rewriting right and are sure what you are trying to do is right, then here's the htaccess code (if you want to redirect http://info.domainname.com/blog/?Tag=somedynamictag to http://domainname.com/tag/somedynamictag).
RewriteEngine On
RewriteCond %{HTTP_HOST} info.domainname.com
RewriteRule ^blog\/\?([A-Za-z0-9]+)=(.*)$ http://domainname.com/$1/$2 [L,R=301]
If that doesn't work, in index.php at http://info.domainname.com/blog/, place the following code:
<?php
header("HTTP/1.1 301 moved permanently");
header("Location:http://domainname.com/blog/tag/".$_GET['Tag']);
?>
And thank you for asking this question. While answering it, I learned many things.
Hope that answers your question,
Peace...
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Url Rewriting Help
How do I get a url ending in /index.php?p=2 to display as /2 instead using .htaccess (pretty urls)?
I currently am working on a webcomic displaying site but I have run into a problem with my .htaccess file. I am trying to rewrite /index.php?p=2 to /2 but for some reason it is not working.
So yeah any help would be much appreciated!
.htaccess can't rewrite /index.php?p=2 into /2. You are approaching the problem in reverse.
Rewrite rules tells Apache to do something when fetching a specific URI. What you really need to do is tell Apache to "rewrite" a request to /2 so that it fetches /index.php?p=2 instead. You can do so with the following RewriteRule:
RewriteRule ^([0-9]+)$ index.php?p=$1 [L]
and then change, in your HTML, every single link to point to the rewritten URI instead of the canonical one. Apache will not "rewrite" your links for you. It will however, with the help of the rule above, fetch the proper resources when the client queries for /2.
Make an .htaccess file similar to this one... (the flags may need to be modified/varied per mod rewrite flag documentation: http://httpd.apache.org/docs/2.3/rewrite/flags.html)
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([A-Za-z_0-9-]+)/?$ index.php?p=$1 [QSA,L]