I use multiple languages. But, I have a problem. This my code not working.
The default language always works.
For example :
www.mysite.com/tr/hakkimizda
www.mysite.com/en/about-us
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} ^dil=([a-z]{2})(?:&|$) [NC]
RewriteRule !^[a-z]{2}/ /%1/%{REQUEST_URI}? [L,NC,R=301]
# default
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} !^dil=.+(&|$) [NC]
RewriteRule !^tr/ /tr/%{REQUEST_URI} [L,NC,R=301]
**language.php**
$dil=$_GET["dil"];
if(file_exists("dil/".$dil.".php")){
$_SESSION["dil"]=$dil;
header("Location:/");
}else{
header("Location:tr");
}
Link type
language.php?dil=tr (location index.php)
language.php?dil=en (location index.php)
I want to be
www.mysite.com/tr/hakkimizda
www.mysite.com/en/about-us
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} ^dil=([a-z]{2})(?:&|$) [NC]
RewriteRule !^[a-z]{2}/ /%1/%{REQUEST_URI}? [L,NC,R=301]
# missing rewrite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-z]{2})/ language.php?dil=$1 [L,NC]
# default
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} !^dil=.+(&|$) [NC]
RewriteRule !^tr/ /tr/%{REQUEST_URI} [L,NC,R=301]
Related
I am trying to rewrite an ugly URL that's using two properties. For example, I want example.com/stories/?url=how-are-you?num=5 to be example.com/stories/how-are-you/5 I have rewritten the first property, but I don't know how to rewrite the num property. Here's my .htaccess file:
RewriteEngine On
RewriteBase /stories/
RewriteCond %{THE_REQUEST} /\?url=([^&\s]+) [NC]
RewriteRule ^ %1? [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?url=$1 [L,QSA]
Try :
RewriteEngine On
RewriteBase /stories/
RewriteCond %{THE_REQUEST} /\?url=([^&\s]+)&num=([0-9]+) [NC]
RewriteRule ^ %1/%2? [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?url=$1&num=$2 [L,QSA]
Results to achieve :
http://example.com/ -> /websites/dispatcher.php
http://another-example.com/ -> /websites/dispatcher.php
http://demo.example.com/ -> /websites/dispatcher.php?subdomain=demo
http://demo.example.com/cat/page.html -> /websites/dispatcher.php?subdomain=demo&path=/cat/page.html
With the .htaccess i have, it's working except for the "demo.exemple.com" who return a 502 error.
# Parse the subdomain as a variable
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} !^www
RewriteCond %{HTTP_HOST} ^([^\.]+)\.([^\.]+)\.([^\.]+)$
RewriteRule ^(.*)$ /$1?subdomain=%1
# Map all requests to the 'path' get variable in distpacher.php
RewriteRule ^distpacher\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /distpacher.php?path=$1 [L,QSA]
I'm having a hard time... any help, please?
Replace your 2 rules by these 2 rules:
# Map all requests to the 'path' get variable in dispatcher.php
RewriteCond %{HTTP_HOST} !^www [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.[^.]+\.[^.]+$
RewriteRule ^/?$ /dispatcher.php?subdomain=%1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^www [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.[^.]+\.[^.]+$
RewriteRule ^(.+)$ /dispatcher.php?subdomain=%1&path=$1 [L,QSA]
I want to redirect request on same page by excepting one page by using .htaccess file. The code that i have used
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
Dose anyone know how i can take condition on a single page named "register.php"? Means i want to open register.php now its open index.php.
Thanks in advance
Change your code to:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(index|register)\.php$ [NC]
RewriteRule ^(.+?\.(php|html?|feed|pdf|raw)|[^.]*)$ index.php [L,NC]
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(index\.php|register\.php)$
RewriteRule ^(.*)$ index.php? [L,R=301,E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
i have a Problem with my .htaccess/mod_rewrite:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^sometest/(.+)/page/([0-9]+)$ index.php?main=sometest/$1&page=$2
RewriteRule ^(.+)$ index.php?main=$1 [QSA]
This does not work. If i visit my website the css files are not included.
I include them like "/assets/css/blabla.css".
If i delete just one RewriteRule (doesn't matter which one) it works. But i need both rules.
You must use skip flag skip|S=numfor this.
like :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d [NC,OR]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_URI} ^(.*)/([^/]+)\.([^/]+)$
RewriteRule ^ - [S=2,L]
RewriteRule ^sometest/(.+)/page/([0-9]+)$ index.php?main=sometest/$1&page=$2 [S=1,L]
RewriteRule ^(.+)$ index.php?main=$1 [QSA,L]
see this page for more information http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
I would like to add www into the URL if the users forgot to type and still supporting MVC by redirecting to the index.php with [QSA]
This is my current working .htaccess
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L,QSA]
Using this .htaccess everything works fine, I can type www.abc.com/xxx/yyy to visit any specific pages
Anyway because I'm using Facebook authentication so I must prevent my users from typing the site URL without www, so I tried to edit my .htaccess
RewriteCond %{HTTP_HOST} ^abc\.com$
RewriteRule ^(.*)$ http://wwww.abc.com/$1 [R=301,QSA]
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L,QSA]
With this configuration if I typed abc.com I was redirected to www.abc.com, but if I typed abc.com/xxx/yyy I was only redirected as www.abc.com instead of being redirected to the specific page.
I also tried
# 1
RewriteCond %{HTTP_HOST} ^abc\.com$
RewriteRule ^(.*)$ http://wwww.abc.com/$1 [QSA]
# 2
RewriteCond %{HTTP_HOST} ^abc\.com$
RewriteRule ^(.*)$ http://wwww.abc.com/index.php [QSA]
# 3
RewriteCond %{HTTP_HOST} ^abc\.com$
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://wwww.abc.com/$1 [L,QSA]
None of them is working, please guide what to do
Thanks.
Add this 2 lines above your .htaccess file
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
so your final htaccess will look like this
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L,QSA]