1

This is my .htaccess code.

RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)/$ movie.php?name=$1
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example\.in$
RewriteRule ^/?$ "http\:\/\/example\.in" [R=301,L]
ErrorDocument 404 /404.php
AddDefaultCharset UTF-8
Header unset ETag
FileETag None

I need a clean URL for my website. I've consulted lots of tutorials and forums and created the above code. But it's not working. Almost I'm fighting with code. I don't understand the clean URL concept clearly. Are there any codings I have to write in my PHP file?

<a href='movie.php?name=titanic'> Titanic </a>

I have this link in my index.php file.

I'd like example.in/movie/titanic when I click on the link "Titanic".

Also I'd like to get the value by $_[request].

What exactly do I have to do? Please don't mark this question as duplicate, I've searched a lot and haven't got the concept clearly. Please help me out.

Thanks.

2
  • 1. You have double RewriteEngine On; 2. Turn this RewriteRule ^([a-zA-Z0-9]+)/$ movie.php?name=$1 into this RewriteRule ^movie/([a-zA-Z0-9]+)$ movie.php?name=$1. Now you can get the movie name from $_GET['name']. Commented Jul 31, 2014 at 6:57
  • Put SEO url in href, not old url. Commented Jul 31, 2014 at 6:58

2 Answers 2

1

The rules in .htaccess work on url's relative to the directory your .htaccess file is in. If you have a .htaccess in your www-root, then the first argument of RewriteRule will match everything behind the domain name and before the query string (movie/titanic in http://example.com/movie/titanic?is=amovie). To fix the rule, you need to change the rule to:

RewriteRule ^movie/([a-z0-9]+)/?$ movie.php?name=$1 [L,NC]

The [L] flag stops rewriting for this round, the [NC] flag ignores case.

Besides that, you only need one RewriteEngine on, which needs to be above all rules you write. You can safely delete the second one.

Sign up to request clarification or add additional context in comments.

Comments

0

You can put your .htaccess into main Directory:

RewriteEngine On
RewriteRule ^movie/([a-zA-Z0-9]+)(/)$ movie.php?name=$1 [L]

Or in movies/ directory:

RewriteEngine On /movies/
RewriteRule ^([a-zA-Z0-9]+)(/)$ ../movie.php?name=$1 [L]

While movie.php is in main Directory located.

RewriteEngine On can by starterd only once per htaccess.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.