1

i am new in url rewriting in php htaccess. currently my url as like
http://localhost/htaccess/Movie/my-parameter-value

but i want to http://localhost/htaccess/my-parameter-value
i want remove Movie (movies is from action source name ex "movie.php");
Thanks In Advance

here is my code :

#Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On     
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*?)(?:\+|%20|\s)+(.+?)\sHTTP [NC]
RewriteRule ^ /%1-%2 [L,NE,R=302]

# To externally redirect /dir/foo.php?name=123 to /dir/foo
RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\.php\?name=([^&\s]+) [NC] 
RewriteRule ^ %1/%2? [R,L]     


# To internally forward /dir/foo/12 to /dir/foo.php?name=12
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/([^/]+)?$ $1.php?name=$2 [L,QSA]
4
  • my htaccess located in root directory. because in domianame.com/parameter-value helps to seo boosting for that i have to remove Movie Commented Feb 4, 2016 at 8:19
  • sorry htaccess is my application folder name Commented Feb 4, 2016 at 8:54
  • ya thats the original url Commented Feb 4, 2016 at 12:04
  • ya thats the original url :"localhost/htaccess/Movie.php?name=my parameter value" and i have converted space in dash(-) Commented Feb 4, 2016 at 12:16

1 Answer 1

1

Have it like this:

#Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On     
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*?)(?:\+|%20|\s)+(.+?)\sHTTP [NC]
RewriteRule ^ /%1-%2 [L,NE,R=302]

# To externally redirect /dir/foo.php?name=123 to /dir/foo
RewriteCond %{THE_REQUEST} ^GET\s(.*)/Movie\.php\?name=([^&\s]+) [NC] 
RewriteRule ^ %1/%2? [R,L]     

# /htaccess/Movie.php?name=movie-name => /htaccess/movie-name
RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\.php\?name=([^&\s]+) [NC] 
RewriteRule ^ %1/%2? [R,L]     

# To internally forward /dir/foo/12 to /dir/foo.php?name=12
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/([^/]+)/?$ $1.php?name=$2 [L,QSA]

# handle /htaccess/movie-name internally
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ Movie.php?name=$1 [L,QSA]
Sign up to request clarification or add additional context in comments.

3 Comments

thank's a lot! anubhava you solved my problem i am struggling from months for that thanks.
can i send two parameter name and id but in url show only name not id and in Movie.php can i access that id echo $_GET['id']; ?
No that won't be possible. Once id parameter is removed from URL you cannot retrieve in php file. Having id is a good idea see this question's URL in SO

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.