Rewrite part of url from .htacces - .htaccess

i need to redirect my old url to new url structure
old is http://website.com/mp3/song-name/
new is http://website.com/song-name-mp3-download.html
How can I do this using mod_rewrite?
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^play/(\d+)/.*$ playlist.php?action=shareview&id=$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ search.php?search=$1 [L]
RewriteRule 404.html 404.php
RewriteEngine on
RewriteCond $1 [A-Z]
RewriteRule ^/?(.*)$ /${lowercase:$1} [R=301,L]
<IfModule mod_deflate.c>
<FilesMatch "\.(php|js|css|mp3|wmv|flv|html|htm)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
ErrorDocument 404 /mp3/404.html
</IfModule>

You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^mp3/([^/]+)/?$ $1-mp3-download.html [L,NC,NE,R=302]

Related

PRESTASHOP 1.7 || How to configure Friendly Url with some parameters on CSM customized page?

I have created a custom CMS page on Prestashop, I need to use some parameters to show some information about products. I need it to be friendly though.
The webpage is already configured to be SEO friendly, each new CMS page I create get to has it's own friendly URL, but I need to get the parameter between slashes.
Example:
This is what I got now == prestashopstore.com/items?type=foo
This is what I want == prestashopstore.com/items/foo
This is for the last version of Prestashop
Any ideas? Many thanks for the help.
PD. This is my .htaccess
Options +FollowSymLinks
# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution
# http://www.prestashop.com - http://www.prestashop.com/forums
<IfModule mod_rewrite.c>
<IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On
</IfModule>
RewriteEngine on
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule . - [E=HTTP_AUTHORIZATION:%1]
#Domain: domain.com
RewriteRule . - [E=REWRITEBASE:/]
RewriteRule ^api$ api/ [L]
RewriteRule ^api/(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]
# Images
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$1$2$3$4$5.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg [L]
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]
RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]
# AlphaImageLoader for IE and fancybox
RewriteRule ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 [L]
# Dispatcher
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]
</IfModule>
AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType font/otf .otf
AddType application/font-woff .woff
AddType font/woff2 .woff2
<IfModule mod_headers.c>
<FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|svg)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
</IfModule>
#If rewrite mod isn't enabled
ErrorDocument 404 /index.php?controller=404
# ~~end~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
Try with htacces rules :
<IfModule mod_rewrite.c>
<IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On
</IfModule>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/([^/]*)? $1?type=$2 [NC,N,QSA]
</IfModule>
Regards

.htaccess redirect to different alias

I want to redirect the alias Eg.
http://test.com/mp3 to https://test.com/audio
I had tried this code
<FilesMatch "\.(htaccess|zip|rar)$">
Order Allow,Deny
Deny from all
</FilesMatch>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^mp3$ /audio? [L,R=301]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L,QSA]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
Not work for me . Problem is when i search my site on google and click on any search result it will goes to https://test.com/mp3
Please Help
Thanks
Krishna Karki

htaccess redirection in wamp not working

The .htaccess is working properly when hosted on the server but is not working in wamp. I need to remove the need for /index.php for Codeigniter. Below is my code.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
#AllowOverride All
RewriteBase /
RedirectMatch 403 ^/(application\/cache|codeigniter|\.git|\.hg).*$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
#RewriteRule ^(.*\.html)$ /cms/ [NC]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
</IfModule>
The cause is I forgot to turn on rewrite_module in Apache. :-(

htaccess force www and keep trailing url

I am using the following to redirect my non www. urls to use www.:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "http://www.domain.com/"
</IfModule>
However, if someone visits domain.com/abc-123 it redirects to www.domain.com and loses the remaining of the url.
Any help with this? How can i set it up so it doesn't remove the end of the url?
Miro
Just swap the order of the rules around. Since the first (WP) rule is stripping the path, by the time the second rule is applied the path will be empty.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "http://www.domain.com/"
</IfModule>

Trailing slash remove bug with htaccess

I am having a problem with my htaccess.
when I use this url www.example.com/test or example.com/teste/ its all ok, but when I use a url like this example.com/test it redirects to example.comtest .
I am really cant understand why!
here it is my htaccess:
<IfModule mod_security.c>
# Turn off mod_security filtering.
SecFilterEngine Off
# The below probably isn't needed, but better safe than sorry.
SecFilterScanPOST Off
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# If your server is running PHP in CGI mode you will probably need to uncomment the following lines
# Only uncomment lines that begine with Rewrite
# The RewriteBase should be set to the same value as the AppPath setting in your config.php WITH a / on the end
# RewriteBase /
# This rewrite base rule is only required if you are getting 401 unauthorized errors when placing an order with Google Checkout
# RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
#
# Alternatively, if the above does not work, try uncommenting this line below instead:
# SetEnvIfNoCase Authorization "Basic ([a-z0-9=]+)" REMOTE_AUTHORIZATION=$1
RewriteRule .* - [E=HTTP_IF_MODIFIED_SINCE:%{HTTP:If-Modified-Since}]
RewriteRule .* - [E=HTTP_IF_NONE_MATCH:%{HTTP:If-None-Match}]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]
RewriteRule ^([^\.]+[^/])$ http://%{HTTP_HOST}/$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1
RewriteCond %{REQUEST_URI}\\/%{HTTP_HOST}/www. ^/+(.+/)?[^.]*[^/]\\(/)([^w][^w][^w][^.].*/(www\.)¦.*)$ [OR,NC]
RewriteCond %{HTTP_HOST}/www. ^(/)?(/)?([^w][^w][^w][^.].*/(www\.))$ [NC]
RewriteCond $1 !^(blogg|admin|emailmarketer|favicon\.ico|robots\.txt|index\.php) [NC]
RewriteRule ^ http://%4%{HTTP_HOST}%{REQUEST_URI}%2 [L,R=301]
<IfModule mod_env.c>
SetEnv SEO_SUPPORT 1
</IfModule>
</IfModule>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/x-javascript text/css text/html text/xml
</IfModule>
My guess would be that
RewriteRule ^ http://%4%{HTTP_HOST}%{REQUEST_URI}%2 [L,R=301]
should be
RewriteRule ^ http://%4%{HTTP_HOST}%{REQUEST_URI}/%2 [L,R=301]

Resources