0

This will be a niche question but I am having trouble rewriting my url. I am trying to rewrite from /view.php?user=Alex0111 to view/Alex0111. I also have a second get variable of /view.php?user=Alex0111&id=5 which I want to be view/Alex0111/5 Here are the contents of my .htaccess file

DirectoryIndex Home.php

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^view/([0-9A-Za-z]+) view.php?user=$1 [NC,L] #doesn't work causes internal error

I've checked this line of code multiple times to the tutorial I am following but I am missing the mark on something.

5
  • i also also wanting to ask this questions, thanks for asking by 1+ for you :) Commented Aug 10, 2016 at 7:53
  • Possible duplicate of URL rewriting with PHP Commented Aug 10, 2016 at 7:55
  • Isn't the first RewriteRule rewriting 'view/Alex0111' to 'view/Alex0111.php' ? Commented Aug 10, 2016 at 7:57
  • Are you sure the error is internal 500? Commented Aug 10, 2016 at 8:08
  • Try reordering your rules, put the first rule bellow.. Commented Aug 10, 2016 at 8:10

1 Answer 1

2

Replace both of your rewrite rules with:

RewriteRule ^view/(.+)/(.+)  view.php?user=$1&id=$2  [NC,END,QSA]

Your first rewrite rule will interfere because it will rewrite the path as Markus mentioned in comments.

The [END] flag will throw an error if you have an old Apache version. In that case, use the [L]

The [QSA] flag tells the server to add any additional query parameters that the user sent. eg: view/Alex01/5?param=value

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

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.