Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am having some issues with url rewriting I am using this as my code for rewrite in htaccess

RewriteEngine On
RewriteRule ^([^/]*)\.html$ /pages.php?id=$1 [L]

this was my url

studentsassignmenthelp.com/pages.php?id=Marketing-Assignment-Help

after using the url rewrite i am getting this

studentsassignmenthelp.com/Marketing-Assignment-Help.html

but i need it without the html like the below one

studentsassignmenthelp.com/Marketing-Assignment-Help

if i use the below code to remove the .html than it shows error 500 server...

RewriteRule ^([^/]*)$ /pages.php?id=$1 [L]

I saw some example but after using them it shows 404 or 500 error

share|improve this question
For RewriteRule ^([^/]*)\.html$ /pages.php?id=$1 [L] rule to execute the request URI needs to contain .html in the end. Not as your describing. Also it rewrites a /home.html request to /pages.php?id=home – DevZer0 Jun 14 at 8:49

3 Answers

up vote 1 down vote accepted

Try this,

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !pages.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ pages.php?id=$1 [QSA,L]
share|improve this answer
Thank You........ i worked for me but please explain it so that in future i will have the same problem – Vivek Jun 14 at 9:01
You are welcome... :), and this may be helpful randomtype.ca/blog/the-wordpress-htaccess-file-explained – Nikhil Mohan Jun 14 at 9:24
What i should do if i have more pages like studentsassignmenthelp.com/pages.php?id=Marketing-Assignment-Help studentsassignmenthelp.com/profile.php?id=Vivek – Vivek Jul 10 at 7:25

try this:

RewriteEngine On
RewriteRule ^([^/]*)$ /pages.php?id=$1 [L]
share|improve this answer

redirectMatch 301 ^(.*).html $1

This is quite usefull to remove any url extension and avoid broken links.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.