ruchaidan
ruchaidan

Reputation: 85

Rewriting is not working but gives an internal error in .htaccess

RewriteEngine On
RewriteRule ^http://example.lk/example1/ln1/([^/]*)$ http://example.lk/example1?ln1=$1 [L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^/?$ "http\:\/\/example\.lk\/ln\/1" [R=301,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^contactus$ "http\:\/\/example\.lk\/example3\/cm\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^example\.lk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.lk$
RewriteRule ^example2$ "http\:\/\/example\.lk\/example2\/a\/\$1" [R=301,L]

RewriteCond %{HTTP_HOST} ^example\.lk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.lk$
RewriteRule ^example4$ "http\:\/\/example\.lk\/example4\?\/vi\/\$1" [R=301,L]

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^example6$ "http\:\/\/example\.lk\/example6\/id\/\$1" [R=301,L]


RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^example1$ "http\:\/\/example\.lk\/example1\/ln2\/\$1" [R=301,L]

Upvotes: 0

Views: 50

Answers (1)

Jon
Jon

Reputation: 12992

As pointed out, there a number of errors, please read the manual.

You don't need to double quote or escape the redirect substitutions.

You don't need to match the ${HTTP_HOST} if you don't care what it is.

You can't have a $1 in the substitution without a matching group in the pattern.

I've tried to fix some of the problems... but you need to provide more information on what specifically doesn't work and what you're trying to achieve.

RewriteEngine On
RewriteRule ^example1/ln1/([^/]*)$ http://example.lk/example1?ln1=$1 [L]

# RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^/?$ http://example.lk/ln/1 [R=301,L]

# RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^contactus$ http://example.lk/example3/cm/ [R=301,L]

RewriteCond %{HTTP_HOST} ^example\.lk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.lk$
RewriteRule ^example2$ http://example.lk/example2/a/ [R=301,L]

RewriteCond %{HTTP_HOST} ^example\.lk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.lk$
RewriteRule ^example4$ http://example.lk/example4/vi/ [R=301,L]

#RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^example6$ http://example.lk/example6/id/ [R=301,L]

#RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^example1$ http://example.lk/example1/ln2/ [R=301,L]

Upvotes: 1

Related Questions