I created sub-domain and am working using yii2 framework. .htaccess in subdomain not working.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/(assets|css)
RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L]
RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]
RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css)/
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ frontend/web/index.php
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ frontend/web/$1 [L]
</IfModule>
###Deny accessing dot files
RewriteRule (^\.|/\.) - [F]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
Maybe setting RewriteBase correct your issue. So change your htaccess to this and test:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /path/to/folder # <- Add this line to your htaccess
RewriteCond %{REQUEST_URI} ^/(assets|css)
RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L]
RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]
RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css)/
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ frontend/web/index.php
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ frontend/web/$1 [L]
</IfModule>
###Deny accessing dot files
RewriteRule (^\.|/\.) - [F]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
Related
I want to redirect the url : https://WEB_URL/video?id=1 to https://WEB_URL/video/1
and I have written following htaccess code but it is not working :
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^video/([^.]*)$ video?id=$1 [QSA,L]
My full htaccess code is as follows:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteEngine On
ErrorDocument 404 /login.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# To externally redirect /dir/abc.php to /dir/abc
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)/?$ $1.php [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^video/([^.]*)$ video?id=$1 [QSA,L]
</IfModule>
why it is not working ? What I am doing wrong please help me on this.
Thanks in advance.
Try this:
ErrorDocument 404 /login.php
Options -MultiViews
RewriteEngine On
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /video(?:\.php)?\?id=([^\s&]+) [NC]
RewriteRule ^ /video/%1? [R=302,L,NE]
# To externally redirect /dir/abc.php to /dir/abc
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^video/([^.]+?)/?$ video.php?id=$1 [QSA,L,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+?)/?$ $1.php [L]
I'm trying to add a trailing slash to the url. It nearly works but there is a little problem i don't understand.
When i call the site http://domain.com/test > rewrite to www.domain.com > the trailing slash is added.
When i call the site directly http://www.domain.com/test > nothing is added.
Important to me is that https:// has to be redirected to https:// an not to http://
Here's my config:
############################################
enable rewrites
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !.html
RewriteCond %{REQUEST_URI} !.php
RewriteCond %{QUERY_STRING} !price
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1/ [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1/ [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]
Replace your rules with these simplified rules:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTPS}s on(s)|
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.+?)/?$ http%1://www.domain.com/$1/ [R=302,L,NE]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]
This is my .htaccess code:
AddHandler x-httpd-php5-3 .php
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
RewriteCond %{THE_REQUEST} /welcome/[/?\s] [NC]
RewriteRule ^ / [R=301,L]
You can use this rule in root .htaccess:
AddHandler x-httpd-php5-3 .php
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /welcome[/?\s] [NC]
RewriteRule ^ / [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
I'm trying to implement a solution using .htaccess and wildcard subdomains so that
http://example.com.domain.com is mapped to http://domain.com/www/example.com
. My rules look something like:
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-\.]+)\.domain\.com$ [NC]
RewriteRule !^www/ www/%2%{REQUEST_URI} [PT,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
Try changing the second rule to:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !^www/ index.php [L]
I'm trying to exclude few URI from htaccess based redirection
My htaccess directives are bellow
<IfModule mod_rewrite.c>
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^(www\.)?domain1.com$ [NC]
RewriteRule !=/test$ http://domain2.com [L,R=301,NC]
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
What wrong in this? Any suggesion?
I have tried in a different way as well
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !=/test
RewriteRule (.*) http://domain2.com? [R=301,L]
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
While doing external redirection, exclusion of the the URI, test is not in effect. If I'm doing an internal rewrite, its working fine.
Maybe this works:
Options +FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !/test
# Add next line
RewriteCond %{REQUEST_URI} !index\.php [NC]
RewriteRule (.*) http://domain2.com? [R=301,L]
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>