Sameer K
Sameer K

Reputation: 799

.htaccess - redirect invalid URL

I have the following URL : www.domain.com.au/--xyz-75/

please suggest how do I redirect this url to homepage, i.e to www.domain.com.au using .htacees.

The .htaccess file in public_html folder.

Application is developed in php.

If it is not possible in .htaccess , then is there any other way?

Upvotes: 0

Views: 2035

Answers (5)

Amit Verma
Amit Verma

Reputation: 41249

Try this solution :

RewriteEngine On 
#if requested filename is not a existing file
RewriteCond %{REQUEST_FILENAME} !-f
#if requested filename is not a existing directory
RewriteCond %{REQUEST_FILENAME} !-d 
#Rewrite the url
RewriteRule ^--([^/]+)/?$ http://example.com [R,L]

This redirects :

example.com/--foo 

to

example.com

Upvotes: 0

Mojtaba Rezaeian
Mojtaba Rezaeian

Reputation: 8756

have you tried adding this line of code in your .htaccess file:

Redirect 301 /--xyz-75/ /

this will simply redirect from your url to root which is "www.domain.com.au" in your example.

Upvotes: 1

loler
loler

Reputation: 2587

In .htaccess:

Redirect /--xyz-75/index.php http://www.domain.com.au/

In your PHP file you have many options to do that. With PHP header location:

<?php header("Location: http://www.domain.com.au/"); ?>

With JS, problem is that it will work only if JS is enabled in user's browser:

<script type="text/javascript">
window.location = "http://www.domain.com.au/"
</script>

And with HTML:

<meta http-equiv="REFRESH" content="0;url=http://www.domain.com.au/">

Upvotes: 0

iLaYa  ツ
iLaYa ツ

Reputation: 4017

Try this in .htacces

RewriteEngine on    
Redirect /--xyz-75/ http://www.domain.com.au/

Upvotes: 0

Bud Damyanov
Bud Damyanov

Reputation: 31919

In conjuction with the other answers, the rewrite engine must be turned on in order this soltuion to work,

RewriteEngine on
Redirect /--xyz-75/index.php http://www.domain.com.au/

Another way is to use simple HTML code in index.html (or index.php) file inside your www.domain.com.au/--xyz-75/ folder:

<meta http-equiv="refresh" content="1;URL=http://www.domain.com.au/" />

Upvotes: 1

Related Questions