5

This is my .htaaccess 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 clean url for my website. I've referred lots of tutorials and forums and created the above code. But not working.. Almost I'm fighting with code. I dont understand the clean url concept clearly. Is there any codings I ve to write on my php page.

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

I've this link in my index.php file.

I want example.in/movie/titanic while click the link Titanic.

Also I want to get the value by $_[request].

What exactly I've to do. Please dont make this question as duplicate, I've searched a lot and didn't got the concept clearly. Please help me out.

Thanks

0

3 Answers 3

7

Replace your code with this:

ErrorDocument 404 /404.php
AddDefaultCharset UTF-8
Header unset ETag
FileETag None

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+movie\.php\?name=([^\s&]+) [NC]
RewriteRule ^ movie/%1? [R=301,L]

RewriteRule ^movie/([^/]+)/?$ movie.php?name=$1 [L,QSA]
Sign up to request clarification or add additional context in comments.

7 Comments

I've made changes by ur advise.. But now mt index page is not working properly.. my site is intamil.in U can see wat happen there by visiting my site
I have made an edit. Besides intamil.in seems to be working fine. Explain your problem clearly, what's not working for you.
@RakeshRajan anub's answer looks good to me should work exactly as you requested, you must be having something else causing the issue, so you should clearly tell us what happens and what does not so we can pin point that.
That is the correct way to fix CSS, js issues. Always use full path for them.
@RakeshRajan like anub said, your issue is no longer .htaccess rules, your issue is the fact you're using relative paths for css, js and possible images on your HTML as such <link rel="stylesheet" type="text/css" href="css/my.css"> where it should have been <link rel="stylesheet" type="text/css" href="http://domain.com/css/my.css"> the fact you're using relative path, will make the browser assume it belong to the closest folder on the URL so in your case it assumes the folder /movie/titanic/ as the css folder hence why it fails.
|
2

If you're want to have clean URLs, then you have to use clean URLs in your html code, e.g. use

<a href="/movie/titanic">Titanic</a>

Your rewrite rules will take that doesn't-really-exist-on-the-server address (you don't really have a /movie directory that contains a titanic file, after all), and translates it in to the actual

/movie.php?name=titanic

The user would never see this url, however, because the rewrite would take place purely within Apache. As long as the HTML you send to the user contains only "clean" urls, they'll never see the query strings.

4 Comments

I understand wat u have told.. If every things works fine then how can I get that value "titanic" at movie.php page. I've to fetch something from database depends on this value..
if your rewrite rule is working properly, it'd simply be $_GET['name']. PHP will be invoked as if the user had directly visited example.com/movie.php?name=titanic, but the user will only ever see example.com/movie/titanic in their browser.
Your rewrite rule is requiring the presence of a / at the end of the url, and does not allow for a / in the middle of the url, so /movietitanic/ would match, but /movie/titanic would not.
I dont understand clearly Marc. I'm new to php and strange to .htaccess. But very eager to learn and resolve..
2
RewriteEngine on
RewriteRule ^movie/([0-9a-zA-Z]+)$ movie.php?name=$1 [L]

Add above code in .htaccess file

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.