htaccess get other variables - php

This is my whole .htaccess code:
RewriteEngine on
Options +FollowSymlinks
Header set X-UA-Compatible "IE=Edge,chrome=1"
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
RewriteRule admin/^([^\.]+)$ ./admin.php?get=$1 [L,QSA]
RewriteRule admin/ ./admin.php [L,QSA]
php_value date.timezone "Europe/Bratislava"
I want that, when users are at http://something/admin/ it will show up admin.php - that is this row RewriteRule admin/ ./admin.php [L,QSA] and it works well.
But when users are at http://something/admin/profile/email/ it should send something like admin.php?get=profile/email/, but it doesn't. What is wrong?

Related

redirecting subdomain to main domain with htaccess

I am building a website with two main sections,
so I have created two subdomains:
web1.example.com
web2.example.com
since i'm building websites with codeigniter, I want to redirect to the index.php page. here's what I did:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^web1.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/web1 [R=301,NC,L]
it works as expected, but it changes the url to example.com/web1..
is there any way to keep the url web1.example.com, but still redirecting to example.com/web1?
I already am using .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
when I enter web1.example.com, the actual url to be executed should be:
example.com/web1, and file to be executed is index.php ..
Didnt tested, Modify and try this
RewriteRule ^([a-zA-Z0-9-/]+).example.com$ http://example.com/$1 [L]
RewriteRule ^([a-zA-Z0-9-/]+).example.com/([a-zA-Z0-9-/]+) http://example.com/$1&$2 [L]
Edited 1
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteRule ^(.*)$ http://example.com/index.php/%1&$1 [L,NC,QSA]

What is wrong with this .htaccess? Too many redirects on Safari

can someone pls say me where my .hatcess has a problem?
RewriteEngine On
RewriteRule \.(css|jpeg|jpg|gif|png|js|json|eot|svg|ttf|woff|txt|xml|ico)$ - [L]
RewriteRule . core/FrontController.class.php [L]
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Redirect 301 /index http://eese.com
The problem: Safari says i have to many redirects (Just go to http://eese.com)
Don't use Redirect rule with your mod_rewrite rules. Change your .htaccess to:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^index/?$ / [L,R=301,NC]
RewriteRule \.(css|jpeg|jpg|gif|png|js|json|eot|svg|ttf|woff|txt|xml|ico)$ - [L]
RewriteRule . core/FrontController.class.php [L]
Test this out after clearing your browser cache.

rewrite from http to https results on index.php for any request

I'm using this htaccess code. I expect any call to be directed to https://www.mysite.com/theme/topic. I've really looked lots of links & helps - the result is only and ever:
https://www.example.com/index.php
so the /theme/topic are not in the output url, only the index.php
what is wrong here? thanks for any help
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
### If file exists, use it.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php [L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,QSA,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.com/$1 [L,QSA,R=301]
</IfModule>
you say it yourself:
so the /theme/topic are not in the output url, only the index.php
try to change the line
RewriteRule ^(.*)$ index.php [L]
into
RewriteRule ^(.*)$ /theme/topic/$1 [L]
Or is there a specific reason why not to put it there?
[edit after clarification]
So you have 2 dynamic parameters and want to rewrite yourdomain.com/parameter1/parameter2 to yourdomain.com/index.php?p1=parameter1&p2=parameter2? Then try the following:
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?p1=$1&p2=$2 [L]
[re-edit after more clarification]
Oh, so it is just redirecting from http to https and redirecting to www? Then you can just do the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC, OR]
RewriteCond %{HTTPS} !on
RewriteRule ^.*$ https://www.mysite.com/%{REQUEST_URI} [R=301,L]
</IfModule>

apache rewrite rules issue for specific pages

I have problem with my .htaccess redirections. When I type:
http://www.domain.com/contact
it goes to the index.php and not the contact.php
here's my .htaccess:
Redirect 301 /clients http://clients.domain.com
RewriteEngine On
SetEnvIf Host ^www\. page=www
SetEnvIf Host ^mob\. page=mobile
RewriteBase /
SetEnvIfNoCase User-Agent "^Wget" bad_bo
#etc ...
Deny from env=bad_bot
RewriteCond %{HTTP_HOST} !^www.domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301]
RewriteRule ^about/?$ about.php
RewriteRule ^contact/?$ contact.php
rewriterule ^(.*)$ index.php?subdomain=%{ENV:page}&page=$1
in my php i get:
<?php
print_r($_GET);
Array (
[subdomain] => www
[page] => contact.php
)
What am I missing?
Try this rule:
RewriteCond %{HTTP_HOST} !^www.domain.com [NC]
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
RewriteRule ^about/?$ about.php [NC,QSA,L]
RewriteRule ^contact/?$ contact.php [NC,QSA,L]
rewriterule ^([a-z0-9]+)$ index.php?subdomain=%{ENV:page}&page=$1 [NC,QSA,L]
I also added the NC, QSA, L flags to make sure the last rule [L] is executed if match, [NC] for non case and [QSA] for Query String Append.
You need to rewrite your about and contact rules in the following way:
RewriteRule ^about/?$ about.php [L,QSA]
RewriteRule ^contact/?$ contact.php [L,QSA]

properly structuring an htaccess with multiple rules/conds

How would i properly structure this htaccess file as to correctly function in order and avoid infinite loops?
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301]
RewriteBase /
RewriteRule ^deviceToken/$ devicetoken.php [QSA,L]
RewriteRule ^register/$ register.php [QSA,L]
RewriteRule ^resetPassword/$ resetpassword.php [QSA,L]
RewriteRule ^deleteLink/$ deletelink.php [QSA,L]
RewriteRule ^getLinks/$ getlinks.php [QSA,L]
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)|(\.swf)|(\.xpi)|(\.ico)|(\.src)$
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteRule (.*)$ get.php?code=$1 [L]
It looks OK, have you tried it already?
This line is useless:
RewriteCond %{REQUEST_URI} ^(.*)$
Redirect domain first:
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
(added ,L)

Categories