1

I am having an URL named www.example.com/print?id=adder
I want it to look like www.example.com/print/adder

I am using the following .htacces code

RewriteEngine on

# redirect all requests except only POST
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.(?:php?)[\s?/] [NC]
RewriteRule ^ /%1%2 [R=302,L,NE]

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteRule ^print/([a-z]+) print.php?id=$1 [NC,L]

But still, i am having the URL like www.example.com/print?id=adder.

I am using wamp 3.0.6(Latest Version), PHP 7.0,10 & Apache 2.4.23. Why am i facing this problem. Why isn't the code working?

Akshay Shrivastav
  • 1,115
  • 4
  • 17
  • 43
  • is your htaccess in /print folder? – Amit Verma Feb 12 '17 at 15:04
  • No, my .htaccess is in the root folder & print is not a folder its `print.php`. I have made the .php extensions hidden so you are seeing `print?id=` instead of `print.php?id=` – Akshay Shrivastav Feb 12 '17 at 15:06
  • "But still, i am having the URL like ..." - you also need to change the URL in your application (this is what actually _changes_ the URL) - presumably you have already done this? – MrWhite Feb 12 '17 at 17:19

1 Answers1

1

To redirect your url to cleaner version, put this above your last RewriteRule

RewriteCond %{THE_REQUEST} /print/?(?:\.php)?\?id=([^\s&]+)
RewriteRule ^ /print/%1? [L,R]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
  • your code changes the URL but due to that code its giving an Internal Server Error 500. – Akshay Shrivastav Feb 12 '17 at 15:22
  • Your modified code isn't accepting @starkeen. It's converting into clean URL but its showing the same 500 Error, Internal misconfiguration error – Akshay Shrivastav Feb 13 '17 at 11:57
  • Akshay, I dont think you are getting the error because of this rule. The rule is ok I have tested it on my server. Please check your error log for info about the 500error. – Amit Verma Feb 13 '17 at 12:39