htaccess file ( url rewriting ) - apache

Is possibile convert this url:
http://corpovigiligiuratife.it/promo.php
to
http://corpovigiligiuratife.it/promozione-porta-un-amico
with htaccess MOD Rewrite?
I did several searches but I could not figure out how to convert this url.
I have 2 static 2 url and not a dynamic url.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^promozione-porta-un-amico$ promo.php [L]
</IfModule>

Use this as the content of the .htaccess file:
RewriteEngine On
RewriteRule ^promo.php$ promozione-porta-un-amico [R=301]
It will redirect the user from promo.php to promozione-porta-un-amico
The R=301 means that this link is Moved Permanently.

Related

htaccess simple redirect without changing URL

I'm trying to redirect people who go to my site but I want it to not show in the URL.
http://www.example.com/ -> http://www.example.com/dev/
except the /dev part shows in the URL when the redirection takes place, how do I hide it so it stays as http://www.example.com/? Here's my HTAccess file..
RewriteBase /
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ dev/index.php [L]
</IfModule>
Any help would be appreciated, thanks.

htaccess 301 redirection of urls w/ parameters to url w/o parameters

I would like to do a simple 301 direct on some old URLs that have parameters to them.
e.g.
/dir/page1/?id=4590
/dir/page1/?id=45
/dir2/page5/?id=4590
/dir2/page9/?id=45
/page90/?id=45etc
...
I want a 301 redirect of the above urls to the corresponding urls w/o parameters:
/dir/page1
/dir2/page5
/dir2/page9
/page90
My experience with .htaccess is limited. What would be the simplest and the most correct way to enable the above redirects to actually work.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^id= [NC]
RewriteRule ^ %{REQUEST_URI}? [R=301,L]

Apache htaccess Rewrite rule to append querystring to all css files

I want to append a static query string to all css files on my site. Like styles.css to styles.css?a=1. Is it possible to achieve this through rewrite rules in .htaccess file. If so what's the rewrite rule to be written. thanks in advance. .
add this to the .htaccess file under the root folder of your website, this will this redirect all css requests to the css?a=34 (query shown in the user browser), is that what you want?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.+)\.css$ $1.css?a=34 [R,L]
</IfModule>

.htaccess redirect only URLs contain number at end

I want to redirect every URLs contain number at end to subdomain :
http://example.com/773 to http://blog.example.com/773
and not redirect URLs contain strings like this :
http://example.com/web or http://example.com/web/shop or http://example.com/about
i used this htaccess code :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/[0-9]
RewriteRule (.*) http://blog.example.com/$1 [R=301,L]
</IfModule>
but this htaccess code redirect URLs like this :
http://example.com/773 to http://blog.example.com/blog/773
The rule below will redirect ONLY this sort of URLs only: http://example.com/773. If URL will be like http://example.com/somfolder/773 (with some folder in the path) then nothing will happened.
RewriteEngine On
RewriteBase /
RewriteRule ^(\d+)$ http://blog.example.com/$1 [R=301,L]

Redirect using .htaccess

I want to redirect all user page requests to a page on the same domain.
For example, I have an "under construction, BRB" page that I want all users to see when they try to access ANY page on the site.
I tried using this:
Redirect 302 / http://www.domain.com/index2.php
What that does is try to apply the redirect to the index2.php page as well and it gets stuck in a loop where the user then sees this until the browser stops.
http://www.domain.com/index2.phpindex2.phpindex2.phpindex2.php etc., etc,
Any idea on how to write that rule to except that page?
You have to exclude the file you want to redirect to. Here’s an example with mod_rewrite:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule !^index2\.php$ /index2.php [L,R=302]
</IfModule>
To prevent endless looping (index2.php <--> index2.php):
Only redirect If URL to be redirected does NOT contain the string 'index2.php'
RewriteCond %{QUERY_STRING} !index2.php
RewriteRule ^(.*)$ /index2.php [L,R=301]
You could use mod_rewrite
<IfModule mod_rewrite.c>
RewriteCond {REQUEST_URI} !=/index2.php
RewriteEngine on
RewriteRule ^.*$ /index2.php
# End .HTACCESS
</IfModule>
I'd be more inclined to use the slightly different
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/.*$ /index2.php [R=307,L]
</IfModule>
This will let you return a moved temporarily status for the redirect.
Omitting this set of flags means that mod_rewrite will return a 302 Found status by default.
HTH
cheers,