.htaccess RewriterRule - redirecting to index of site - .htaccess

I've got the following Rewrite:
RewriteEngine On
Options +Indexes
RewriteRule ^/#/why-us/44534/$ http://www.new-site.com/why-us/? [R=301,NE,NC,L]
RewriteRule ^/#/about-us/33945/$ http://www.new-site.com/about-us/? [R=301,NE,NC,L]
I've put this in the .htaccess file in the root of my site. However, when visiting:
www.old-site.com/#/why-us/44534 I just get the 'Index of /' page for old-site.com
Not sure why the url structure of old site has /#/ at the start, but it's not something I can control!

It is because browser doesn't send any request to web server for URL part after hash sign that's why for a URL of: www.old-site.com/#/why-us/44534 browser just sends www.old-site.com/ to web server while trying to scroll down page to an undefined tag why-us/44534.

Related

My htaccess passthrough rule redirects to the url instead

I'm trying to passthrough (not redirect!) an empty old page to its new location using an htaccess RewriteRule.
I essentially want the user to browse to mysite.com/page-old and to see that url in their browser but be delivered the content from mysite.com/page-new. The user should not be aware that the location changed.
RewriteEngine On
RewriteRule ^page-old/?$ /page-new [PT]
The actual result is that they are redirected to page-new instead.
I found the below on apache.org which seems to validate my code some, but this is giving me a 404 error.
Description:
Assume we have recently renamed the page foo.html to bar.html and now want to provide the old URL for backward compatibility. However, we want that users of the old URL even not recognize that the pages was renamed - that is, we don't want the address to change in their browser
https://httpd.apache.org/docs/trunk/rewrite/remapping.html
RewriteRule "^/foo\.html$" "/bar.html" [PT]
RewriteEngine On
RewriteRule ^example/my-stuff/$ /example/home/ [L,R=301]
check this answer as well
How to redirect a specific page using htaccess

How do I redirect a web URL using .htaccess

I want to redirect users who enter this website URL:
http://www.myWebsite.com/bananas
to:
http://www.myWebsite.com/fruits/bananas
I cant test it because I'm sending this to somebody.
I have these but I don't know for sure which one works:
RedirectMatch 301 http://www.myWebsite.com/bananas(.*) http://www.myWebsite.com/food/bananas $1
Options +FollowSymlinks
RewriteEngine on
rewriterule ^bananas(.*)$ http://www.myWebsite.com/food/bananas $1 [r=301,nc]
Please specify if you want to redirect or rewrite. The rules you are using serve different purposes and you used both in your example.
Redirect: Actually load a different site when entering the url (end up at url and content of /fruits/bananas)
Rewrite: Url stays the same but server provides rewritten content (url stays at /bananas, but show /fruits/bananas content)
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
Also it is not clear if you only want one single directory to be redirected or all files that are contained in that directory.
Checkout this as a guide: http://www.htaccessredirect.net/
I believe you are looking for
Redirect 301 /bananas http://www.myWebsite.com/fruits/bananas
The HTTP 301 stands for Moved Permanently.
I haven't tested it, though.

Use of page to redirect

I need to set up a page to redirect from our old server to our new server, advising people of the new URL and to change their bookmarks. I know how to use the refresh meta tag in HTML to do this.
But I also want to set it up so that they would see the redirect page no matter what page they have navigated to on the old server. I see several solutions using 301 redirect.
How would I do both? We're running an Apache server on Debian server.
You need to use Apache an RewriteRule using mod_rewrite. This can be placed in an .htaccess file on your server’s root, or it can be placed directly into your Apache config file.
So let’s say your new redirect page—where you explain the site has moved and have set a refresh meta tag—is called redirect.php, then this is the Apache RewriteRule that should work for your needs.
RewriteEngine on
RewriteRule ^(.*)$ /redirect.php [L,R=301]
This will grab any URL on the site this RewriteRule is placed on & redirect them to /redirect.php. That /redirect.php can also be a full URL such as http://mysite.com/redirect.php or anything else.

Using .htaccess to change what URL is being displayed, but without actually redirecting the content?

I have a RewriteRule setup to change
http://kn3rdmeister.com/blog/post.php?y=2012&m=07&d=04&id=4
into
http://kn3rdmeister.com/blog/2012/07/04/4.php
but that actually redirects where the browser is getting the page from. I want to still display
/blog/post.php?y=xxxx&m=xx&d=xx&id=xx
but have the browser show the simpler URL like
/blog/post/year/month/day/id.php
I read something somewhere about using ProxyPass, but I don't quite know what I'm doing :P
I want people to be able to visit either the post.php URL with the query strings, OR the clean URL with fancy shmancy subdirectories for the dates and get the same content — all while displaying the clean URL in the end.
You want something like this:
# First if someone actually requests a /blog/post.php URL, redirect them
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /blog/post\.php\?y=([0-9]{4})&m=([0-9]{2})&d=([0-9]{2})&id=([0-9]*)\ HTTP/
RewriteRule ^blog/post\.php$ /blog/%2/%3/%4/%5.php [R=301,L]
This will redirect the browser to the /blog/##/##/##/##.php URI, that will show up in their address bar. Once they get redirected, the browser will then send a request for /blog/##/##/##/##.php and your server then needs to internally rewrite it back:
# We got pretty URLs, but need to rewrite back to the php request
RewriteRule ^blog/([0-9]{4})/([0-9]{2})/([0-9]{2})/([^\.]+)\.php$ /blog/post.php?y=$1&m=$2&d=$3&id=$4 [L]
This changes everything back internally so that the file /blog/post.php can handle the request.

seo friendly url and redirect

I finally found a way to remove get parameters from my urls
i had url like
/s.com/file.php?name=somthing
with this code i changed them to s.com/file/somthing
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^file/(.*?)$ http://s.com/file.php?name=$1
so far everything is ok
in my local host when i click on a url like s.com/file/somthing it goes exactly to the url
but in my server it redirects to old url and shows old url
i dont want to display my old url
can someone help?
http redirects are always external => visible in the browser. Try that:
RewriteRule ^file/(.*?)$ /file.php?name=$1

Resources