473,385 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

redirect url to some other url using .htaccess

194 100+
Hi everyone,

I am using following code into my .htaccess file at root folder of my webpage:

Expand|Select|Wrap|Line Numbers
  1. Options +SymLinksIfOwnerMatch
  2. RewriteEngine on
  3.  
  4. rewritecond %{http_host} ^mywebsite.com [nc]
  5. rewriterule ^(.*)$ http://www.mywebsite.com/$1 [r=301,nc]
  6. RewriteRule ^([a-zA-Z0-9_-]+)$  index.php?page=$1 
  7. RewriteRule    ^myarticle/([A-Za-z0-9-]+)/?$    index.php?page=my-article&id=$1    [NC,L]  
  8. RewriteRule    ^mytest/([A-Za-z0-9-]+)/?$    index.php?page=mytest&id=$1    [NC,L]    
  9.  
I have no problem with the above code. But i want to prevent the following URL using .htaccess. Because this file exist on the main root and i can't check to see if it exists or not exist. The only way i understand is using .htaccess so that nobody can access it using this way.

Expand|Select|Wrap|Line Numbers
  1. http://www.mywebsite.com/mytest.php
  2.  
Please help me on this.

Also is there anyway i can disallow Search Engine bots to not index these type of URL if found on the website using .htaccess?

Thanking you.
May 20 '11 #1
1 1456
I really don't understand what you want to do but if you want to verify if a file exists with htaccess here is the code
Expand|Select|Wrap|Line Numbers
  1. RewriteEngine on
  2.  
  3. RewriteCond  mytest.php !-f #if file doesn't exist do something
  4. RewriteRule ^/mytest.php$ http://website.com/denied [L,R=301] #this is just for show you can do whatever you want here
  5.  
If you want to avoid getting a page indexed use the robots.txt (this should be respected by all search engines).
robots.txt documentation
May 26 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: timothy ma and constance lee | last post by:
Sirs How can i use javascript to redirect the url in the drop list box once the event onchnage is triggered?
4
by: Dave | last post by:
Hi, Is there anyway to mimic forms authentication's loginUrl and RedirectFromLoginPage functionality using Windows authentication? We are developing intranet sites using basic authentication...
2
by: AAOMTim | last post by:
Depending on user permissions, I would like to be able to change a redirect to disallow certain users from going to a bookmarked page for which they should have no access. Is there a way to modify...
0
by: asnowfall | last post by:
After logging in, I am not able to redirect to the target url; and this happens only when I connect to the website using "http://machine- name:portname"; but not if I connect using either...
2
by: RuthC | last post by:
Hi. I am using .htaccess to redirect in my website Now I want to redirect a url, which Contain '-' to another url. ex: RewriteRule ^book-and-magazine-discount/ query.php?q=$1.
0
by: RobertTheProgrammer | last post by:
Hi folks, I need to combine these two functions and I'm not sure how to go about it. I know how to use .htaccess to prevent anyone from hotlinking the images on my site. What I basically want...
6
by: Doug Laidlaw | last post by:
Jerry Stuckle wrote: I have never used anything but Apache, but I didn't know that .htaccess was server-specific. How does Windows do it? Doug.
6
by: vjayis | last post by:
Hi i m using htaccess to rewrite my urls., In this instead of http://www.mysite.com/index.php i want the url as http://www.mysite.com/home/ any ideas?? and also i m using the following...
3
by: canabatz | last post by:
Hello all!! i got a small problem ,not big :) i got this example of a link in my site that display everything correctly! http://www.mysite.com/product.php?id=200 now my problem is : if...
2
by: jesuraja | last post by:
I am new in ASP.Net and C#. I have used HttpContext.Current.Response.Redirect in a class file. Is it right? or if any problem occur by using this? Thanks
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.