Frage

I know there are tons of posts on here already describing this exact same problem, but I've been looking through them and trying the different solutions to no avail.

I'm attempting to rewrite a URL with a query string at the end and write the value of the query string into the end of the URL. I've tried numerous patterns from numerous answers, but I keep getting either no change in the URL or a 500 Internal Server error.

Here's my htaccess:

RewriteEngine On
Options +FollowSymlinks
Options All -Indexes
ErrorDocument 404 http://domain.com/oh/shit/you/broke/the/internet
RewriteRule ^oh/shit/you/broke/the/internet$ /404.php [L]
RewriteRule ^email/([^/]+)/?$ /email/?name=$1 [L,NC,QSA]

I want http://domain.com/email/?name=blah to be rewritten to http://domain.com/email/blah

What am I missing here?

================

EDIT:

After looking through the logs, I'm seeing a lot of the following errors:

Invalid command '^email/([^/]+)/?$', perhaps misspelled or defined by a module not included in the server configuration
Invalid command '^/email/([^/]+)/?$', perhaps misspelled or defined by a module not included in the server configuration
File does not exist: /home/username/domain.com/email/blah

Here's the full htaccess file after including the fix:

RewriteEngine On
Options +FollowSymlinks
Options All -Indexes
ErrorDocument 404 http://domain.com/oh/shit/you/broke/the/internet
RewriteRule ^oh/shit/you/broke/the/internet$ /404.php [L]
RewriteCond %{THE_REQUEST} \s/+email/?\?name=([^\s&]+) [NC]
RewriteRule ^ /email/%1? [R=301,L]
RewriteRule ^email/([^/]+)/?$ /email/?name=$1 [L,NC,QSA]
War es hilfreich?

Lösung

You have bad syntax. Your code doesn't have RewriteRule keyword.

Try this rule:

RewriteEngine On
Options +FollowSymlinks
Options All -Indexes

RewriteCond %{THE_REQUEST} \s/+email/?\?name=([^\s&]+) [NC]
RewriteRule ^ /email/%1? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^email/([^/]+)/?$ /email/?name=$1 [L,NC,QSA]
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top