-1

I'm getting mad ... please help me:

Going from subdomain.domain.net/short/index.php?link=abcd to subdomain.domain.net/short/abcd

I tried

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^short/(.*)$ short/index.php?l=$1&%{QUERY_STRING} [NC,L]

But I always only get Error 500 or 404

Any suggestions for a potato?

Thank you

Found a solution:

RewriteEngine on
RewriteBase /short
RewriteRule ^(.*)$ index.php?l=$1&%{QUERY_STRING} [L]
Fridleif
  • 11
  • 1
  • 3
  • I don't think I've ever seen `&%{QUERY_STRING}` used with RewriteRule before. People generally reach for the QSA (querystring append) flag. But you can avoid this altogether if you instead move querystring tampering to PHP: `$_SERVER['REQUEST_URI']` then use PHP logic to determine the "abcd" part. Keeping the .htaccess file as generic as possible is usually a good idea so you can handle more specific logic like this at the application layer. Since you're working with a subdirectory, you probably want to rewrite from the base via a leading slash: `/short/index.php` etc. – Kevin Y May 24 '22 at 06:09
  • You might also check your .htaccess file is being read and that mod rewrite is enabled. https://stackoverflow.com/questions/7337724/how-to-check-whether-mod-rewrite-is-enable-on-server – Kevin Y May 24 '22 at 06:28
  • URL rewriting works in the exact opposite way: from `example.com/short/abcd` to `example.com/index.php?a=short&b?=abcd` – Honk der Hase May 24 '22 at 06:32
  • An http status 404 indicates that the requested resource has not been found, so most likely that your rule does not get applied. An http status 500 indicates an _internal_ error for which you will have to consult your http server's error log file to learn about the details. – arkascha May 24 '22 at 06:39

0 Answers0