Ad

The Htaccess RewriteRule For My Redirect Is Not Working

- 1 answer

I would like to redirect this URL:

www.example.com/index.php?id=16632

to this URL:

www.example.com/downloads/patterns

I tried to use this RewriteRule in the .htaccess file of my typo3 installation:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=16632$
RewriteRule ^/index\.php$ /downloads/patterns [R=301,L]

but it is not working. Is anything wrong with the syntax in the RewriteRule? Or is there a conflict with other rules (which were already in the standard htaccess file from typo3):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=16632$
RewriteRule ^/index\.php$ /downloads/patterns [R=301,L]

RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)\1$
RewriteRule ^.*$ - [E=CWD:%2]


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ %{ENV:CWD}$1.$3 [L]


RewriteRule _(?:recycler|temp)_/ - [F]
RewriteRule fileadmin/templates/.*\.(?:txt|ts)$ - [F]
RewriteRule ^(?:vendor|typo3_src|typo3temp/var) - [F]
RewriteRule (?:typo3conf/ext|typo3/sysext|typo3/ext)/[^/]+/(?:Configuration|Resources/Private|Tests?|Documentation|docs?)/ - [F]


RewriteCond %{REQUEST_URI} "!(^|/)\.well-known/([^./]+./?)+$" [NC]
RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule (?:^|/)\. - [F]

RewriteRule ^(?:typo3/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^.*$ %{ENV:CWD}index.php [QSA,L]

If anyone could help me I would be very greatful.

Thank you!

Ad

Answer

Your rule dosn't work because it has a leading slash in the pattern. You can't use a leading slash in RewriteRule if you are using it in htaccess.

This should work :

RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=16632$  
RewriteRule ^index\.php$ /downloads/patterns? [R=301,L]

An empty question mark ? at the end of the rewrite destination is important as it discards old query string from the new location.

Ad
source: stackoverflow.com
Ad