subdomains with only .htaccess - .htaccess

i got url link region ex. http://mysite.it/index.php?page=search&sRegion=Toscana
is possible make with htaccess an url like toscana.mysite.it
Thank for answers
This is my htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mysite\.it$ [NC]
RewriteCond %{QUERY_STRING} (^|&)sRegion=([^&]*) [NC]
RewriteRule ^index\.php$ http://%2.%{HTTP_HOST}%{REQUEST_URI} [R=301,NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mysite\.it$ [NC]
RewriteCond %{QUERY_STRING} (^|&)sRegion=([^&]+) [NC]
RewriteRule ^index\.php$ http://%2.%{HTTP_HOST}%{REQUEST_URI} [R=302,NC,L]

Related

url rewriting with QUERY_STRING

I would like to rewrite http://example.com/test/index.php?id=123
to http://example.com/test/item/123/ and http://example.com/test/index.php?id=123 redirect to the human friendly url.
I don't know what is wrong in my htaccess :
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /test/
RewriteCond %{QUERY_STRING} ^id=([a-z0-9]+)$ [NC]
RewriteRule ^/item/%1/? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^item/([a-z0-9]+)/$ index.php?id=$1 [L]
You can use the following RewriteRule in your /test/.htaccess file
Options +FollowSymLinks -MultiViews
RewriteEngine on
#redirect old url to the new one
RewriteCond %{THE_REQUEST} /test/index\.php\?id=([^\s]+) [NC]
RewriteRule ^ /test/item/%1? [L,R=301]
#internally map new url to the old one
RewriteRule ^item/(.+)/?$ /test/index.php?id=$1 [L,NC]

htaccess mod_rewrite URL problems

I would like to re-write this url here;
site.com/product.php?s=electricity-at-work-regulations
to
site.com/courses/electricity-at-work-regulations
so change product.php to courses and generally tidy the url up.
Is this possible?
.htacess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^peoplefactor.co.uk$ [NC]
RewriteRule ^(.*)$ http://peoplefactor.co.uk/$1 [L,R=301]
</IfModule>
# Clean URLS
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteRule ^blog/([a-zA-Z0-9-/]+)/preview$ /blog/post.php?s=$1&preview=all [L]
RewriteRule ^blog/([a-zA-Z0-9-/]+)$ /blog/post.php?s=$1 [L]
RewriteRule ^course/([a-zA-Z0-9-/]+)$ /course.php?s=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>
# Gets rid of www.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
</IfModule>
Yes but it would be better the other way around.
You should always call site.com/courses/electricity-at-work-regulations within your application and reroute it to site.com/product.php?s=electricity-at-work-regulations. Something like
RewriteEngine On
RewriteBase /
RewriteRule ^(courses)/([a-zA-Z\-]+)$ product.php?s=$2 [L]

.htaccess redirect example.com/magento/index.php to example.com/?

I have Magento installed in a subdirectory, the path to Magento is example.com/magento.
I have an .htaccess file in the root, 'example.com' as follows:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{http_host} ^example.com [NC]
RewriteRule ^magento/(.+)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/magento(/.*)?$ [NC]
RewriteRule ^(.*)$ /magento/$1 [QSA,L]
In the standard Magento .htaccess in example.com/magento I have uncommented the RewriteBase directive as follows:
RewriteBase /magento/
But when I type example.com the browser shows example.com/magento
How could I solve this issue?
Leave RewriteBase commented
# RewriteBase /magento/
Try this, instead, in your /.htacccess:
RewriteEngine on
RewriteRule ^(.*)$ /magento/$1 [L]
RewriteRule ^(.*)$ /index.php/$1 [L]
and add this to your magento/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . / [L]
</IfModule>

how to shorten url using htaccess

Hello guys i need to shorten my url using htaccess
like
Before
www.mysite.com/obj/task/profile/id/1568/username
after
www.mysite.com/1568/username
or
Before
www.mysite.com/obj/task/page/city/41280/pageId/22/clubs//Test%20town
after
www.mysite.com/41280/22/clubs//Test%20town
how can i achieved this using htaccess
my htaccess file has this
RewriteEngine on
Options +FollowSymlinks
Options -Indexes
RewriteCond %{REQUEST_URI} (.+)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
AddDefaultCharset utf-8
RewriteRule (.*) index.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^test.com [NC]
RewriteRule ^(.*)$ http://www.test.com/$1 [L,R=301]
Suggested Changed
<files .htaccess>
order allow,deny
deny from all
</files>
php_value memory_limit 170M
RewriteEngine on
Options +FollowSymlinks
Options -Indexes
RewriteCond %{REQUEST_URI} (.+)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
AddDefaultCharset utf-8
RewriteRule (.*) index.php
#RewriteCond %{HTTPS} !=on
#RewriteCond %{HTTP_HOST} !^$ [NC]
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# THIS RULE FOR FOR INACTIVE HTTPS
#RewriteCond %{HTTP_HOST} !^www.*$ [NC]
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# from /obj/task/profile/id/1568/username
# to /1568/username
RewriteRule ^obj/task/profile/id(/.+)$/$1 [R=302,L,NC]
# from obj/task/page/city/41280/pageId/22/clubs//Test%20town
# to 41280/22/clubs//Test%20town
RewriteRule ^obj/task/page/city/([^/]+)/pageId(/.+?)/?$ /$1/$2 [R=302,L,NC,NE]
I have visited www.mysite.com/obj/task/profile/id/1568/username
The links is still not shorten.
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 /
# from /obj/task/profile/id/1568/username
# to /1568/username
RewriteRule ^obj/task/profile/id(/.+)$ /$1 [R=302,L,NC]
# from obj/task/page/city/41280/pageId/22/clubs//Test%20town
# to 41280/22/clubs//Test%20town
RewriteRule ^obj/task/page/city/([^/]+)/pageId(/.+?)/?$ /$1/$2 [R=302,L,NC,NE]

Wrong 301 htaccess redirection

I have this code on my site and I need to redirect the http://softsolutions.fr to http://www.softsolutions.fr, but it is not redirecting:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
Options +Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} ^softsolutions\.fr
RewriteRule ^(.*)$ http://www.softsolutions.fr/index.html [R=301,L]
RewriteRule ^$ /index.html [L]
# Rewrites "sub.domain.foo/anything" to "sub.domain.foo/anything.php"
RewriteCond %{REQUEST_FILENAME} !^(.+).php$
RewriteCond %{REQUEST_FILENAME} !^(.+).pdf$
RewriteCond %{REQUEST_FILENAME} !^(.+).(html|htm)$
RewriteRule ^([a-zA-Z0-9\-\_/]*)$ /$1.php [L]
</IfModule>
Replace those lines:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^softsolutions\.fr
RewriteRule ^(.*)$ http://www.softsolutions.fr/index.html [R=301,L]
With:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^softsolutions\.fr [NC]
RewriteRule (.*) http://www.%{HTTP_HOST}%{REQUEST_URI}

Resources