Multilanguage site, subdirectories as language (RewriteRule) WHMCS - .htaccess

I went to make friendly urls for my web using RewriteRule as I'm using whmcs and the script is encoded. Here is what I want:
http://www.example.com/index.php?language=english
to
http://www.example.com/en/index.html

Try this
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^en/(.*)\.html$ /$1.php?language=english [L,QSA]
</IfModule>

Related

.htaccess masking URL for subdomain

Our site's sub-domain reading.domain.com has the content that we want people to see but the URL should be domain.com/reading.
I'm not an expert in URL rewriting but I tried to edit htaccess, but it only redirects the page.
We're using siteground, does hosting company has something to do with their apache configuration to make this work?
Thank you very much.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^reading/$? domain.com/reading/ [R,L]
</IfModule>
I figured it out, thanks for the insight #Panama Jack, [P] = it real does need proxy, [NC] case-sensitive, [L] use this rule one time.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^reading/?$ http://reading.domain.com/ [P,NC,L]
</IfModule>

htaccess to rewrite ASP to PHP with query string param change

I recently changed from an ASP site to a PHP site and I need to rewrite the old URL style to a new style. For example:
www.mydomain.com/store/list_view.asp?itemid=1000645
To this:
www.mydomain.com/store/list_view.php?id=1000645
so far I can get an ASP request to redirect to a PHP page using this:
RewriteEngine on
RewriteRule ^(.*)\.asp$ /$1.php [R=301,NC]
I'd appreciate any help that you can provide and if possible an explanation of how it works, I'm new to working with redirects and .htaccess.
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} ^itemid=(.+)$ [NC]
RewriteRule ^(.+?)\.asp$ $1.php?id=%1 [R=301,L,NC]
It matches QUERY_STRING for itemid parameter and captures it's value in %1 via RewriteCond. Then it replaces .asp by .php and adds id=%1 to complete the target URL.

Using vars for specific urls in htaccess

I'm editing htaccess for the first time and don't know how to write proper urls redirectings.
I googled that problem, but there are just no answers for redirecting, only rewriting.
I have links like /?post=89 on my site and I wanted to redirect them to /stranica/89/
Could you possibly help me, how to use vars to catch that number and redirect correctly?
Tried suggested solution, didn't work. I'm seeking for something like this
Redirect index.php/?post=$ /stranica/$1/
but that code is not working.
If you have different querystring patterns in your site, you can try this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)=(.*)
RewriteRule ^(.*).php /$1/%1/%2/? [R,L]
</IfModule>
This will redirect urls like /index.php?id=5 to /index/id/5/
The below code will redirect the exact url which you mentioned on your question
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^post=(.*)
RewriteRule ^index.php /index/stranica/%1/? [R,L]
</IfModule>

.htaccess only redirect index.php to new site

We are working on our new site, and we want to make the homepage re-direct to a subdirectory I am wondering how to do this with .htaccess as then any other page they need to go back to the old site.
These rules will forward http://yourdomain.example.com to http://yourdomain.example.com/yoursubdir/
RewriteEngine on
RewriteRule ^/?$ yoursubdir/ [L]
If you want, instead, to redirect an URL with index.php (like http://yourdomain.example.com/index.php use this rules instead.
RewriteEngine on
RewriteRule ^index.php$ yoursubdir/ [L]
In general have a look at the documentation of mod_rewrite. There are many useful and free guides around the net.
Something like this should do the trick
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/some/subdir/$1 [R=301,L]
This will rewrite the requested URI to some/subdir of newdomain.com

cakephp .htaccess with multiple domains

I have my cakephp .htaccess files set up as in the cookbook and everything is working fine.
My web site currently has multiple domains, all of which point to the same site (e.g. www.site.com, www.site.co.uk). I'd like to set up a rule so that requests to www.site.co.uk/page are permanently redirected to www.site.com/page, etc.
I'm having trouble getting both rules to work together. Can anyone help me out?
EDITED TO INCLUDE FURTHER DETAILS:
Here is the .htaccess file in my web root:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
# Force domain to be www.site.com
RewriteCond %{HTTP_HOST} !^www\.site\.com$
RewriteRule ^(.*)$ http://www.site.com/$1 [R=permanent,NC]
# For CakePHP
RewriteCond %{HTTP_HOST} ^www\.site\.com$
RewriteRule ^(.*)$ app/webroot/$1 [NC]
</IfModule>
I also have a separate CakePHP app in a subdirectory: tbgroup. Here is the .htaccess file (tbgroup/.htaccess):
<IfModule mod_rewrite.c>
RewriteEngine on
# For CakePHP
RewriteRule ^(.*)$ app/webroot/$1 [NC]
</IfModule>
Everything works as fine: www.site.co.uk is redirected to www.site.com, www.site.co.uk/page is redirected to www.site.com/page. CakePHP works fine. The only problem is www.site.co.uk/tbgroup is not redirected to www.site.com/tbgroup - it remains as www.site.co.uk/tbgroup (and CakePHP works fine).
Try it out on the live site if you like (www.site.com or www.site.co.uk).
I believe that you've pointed out the answer in the permanent redirection link in your question.
It's really not related to cakephp. It's just mod-rewrite issue. You have yo put this code in your .htaccess file (under /app/webroot)
rewritecond %{http_host} ^(www.)?site.co.uk [nc]
rewriterule ^(.*)$ http://site.com/$1 [r=301,nc]

Resources