Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
What will be the code for these redirects in the .htaccess file?
www.site.com/books/ =====> www.site.com/movies/
www.site.com/books/title/ =====> www.site.com/movies/title.html
If you need to do it as 301 redirect (and assuming your htaccess file is in the root folder), then these rules will do the trick:
RewriteRule ^books/$ http://www.example.com/movies/ [R=301,L]
RewriteRule ^books/title/$ http://www.example.com/movies/title.html [R=301,L]
Replace example.com with your domain name.
Search here in S.O. also. There are countless posts on how to do these redirections.
Edit: For dynamic titles the second rule becomes:
RewriteRule ^books/([^.]+)/$ http://www.example.com/movies/$1\.html [R=301,L]
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have seen many websites, which don't have www in their URL, they just magically redirect www.example.com to my.example.com.
I am trying to figure it out who it is done, please guide me
As for my.example.com,this is something related to subdomains, from your hosting you can create subdomain for example my.example.com, and you can upload files to the folder assigned to that subdomain.
for www and non www it can be set from hosting also and from .htaccess file.
https://www.keycdn.com/support/popular-htaccess-examples
For example if you add this to .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]
you can make redirection
You are confusing the prefix www with subdomains. What you want is to add the subdomain 'my' to the domain name 'example.com'
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
i want to redirect in .htaccess all the site meaning if I go to : http://oldsite.com/sdsd.php?cal=343
it will redirect to http://newsite.com/sdsd.php?cal=343
RTFM.
RewriteEngine on
RewriteRule (.*) http://newsite.com/$1 [R=301,L]
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I would like to rewrite this url in APACHE with RewriteRule
http://localhost/info.php?id=1000
to
http://localhost/folder/1000.html
I spent hours to solve this problem but it didn't work.
Without the /folder/ in the pattern it works but adding folder it does not.
This solution works:
RewriteEngine
on RewriteBase /
RewriteRule ^([\w-]+)\.html$ info.php?id=$1
but this does not work:
RewriteRule ^/folder/([\w-]+)\.html$ info.php?id=$1
What is missing
I have found the solution by removing the first slash /
RewriteRule ^folder/([\w-]+)\.html$ info.php?id=$1
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
My current URL is
http://domain.com/directory/page.php
I would like the page to be accessed and addressbar to keep it as
http://domain.com/page
is this possible with htaccess?
You'll need to enable mod_rewrite. Then, you can put something like this in your .htaccess file:
RewriteEngine on
RewriteRule ^/page$ /directory/page.php [L]
If you want to do this for all of the php scripts in /directory/, you could do this instead:
RewriteEngine on
RewriteRule ^/([^/]+)$ /directory/$1.php [L]
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have a problem redirecting a folder to another one.
The rule seems to "work" but it stumble at some point adding some other stuff.
Here an example:
The goal is to redirect traffic from oldfolder (not existing anymore) to newfolder.
www.domain.com/one/oldfolder/year/ --> www.domain.com/one/newfolder/year/
So i set up the following rules (first one for the canonical url):
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^/?$ "http\:\/\/www\.domain\.com" [R=301,L]
RewriteRule ^(.*)/oldfolder/(.*)$ $1/newfolder/$2 [R=301,L]
The problem is that it redirects to:
http://www.domain.com/home/username/public_html/www.domain.com/one/newfolder/year/
Anyone can spot the problem in the rule i wrote?
Thank you very much for your help.
Check your DocumentRoot
Check the Directory directive
Make sure you have RewriteBase / if this .htaccess file is in your document root.