Trying to get
www.example.com/home
to go directly to
www.example.com/
What I've tried:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(.+)\www.example\.com$
RewriteRule ^/(.*)$ /samle/%1/$1 [L]
What am I doing wrong?
but its website rotating always .
Redirect 301 /home http://www.example.com/
If what you are saying is that you want the index function in your "home" controller to be the default homepage, you can set that in routes.php under the route['default_controller'] parameter. That way you don't need to worry about the redirect at all. If you want to remove /home anytime it's typed in, you can use a mod-rewrite like you do to remove index.php from the uri. Check out the docs for more info http://ellislab.com/codeigniter/user-guide/general/urls.html
Related
I have implemented a mod rewrite condition as shown below. Basically I want everyone other than me (from the stated IP address) to be redirected to a certain page on my site. That part works but these directives end up causing endless redirects and the browser times-out.
What might a RewriteCond directive look like to test the page /index.html and not do anymore rewrites if the page is https://example.com/index.html?
# 2016-03-18 redirect everyone except listed IPs
# 123.456.789.012 = my static Work Office address
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^(123\.456\.789\.012)$
RewriteRule ^(.*)$ https://example.com/index.html [R=302,L]
You have to exclude the destination you are redirecting to :
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^(123\.456\.789\.012)$
RewriteCond %{REQUEST_URI} !^/index\.html
RewriteRule ^(.*)$ https://example.com/index.html [R=302,L]
Otherwise you will get a redirect loop error because index.htm also matches the pattern ^(.*)$ .
my website (thedutchtilt.com) employs AJAX.
Now I know that whenever Google tries to crawl a page, e.g. #!stories/component_74511, it will turn that url into thedutchtilt.com/?_escaped_fragment_=stories/component_74511 .
My question is, how do I format a htaccess redirect so that the aforementioned site will map to the other one?
I've tried
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=stories/component_74511
RewriteRule ^$ http://www.thedutchtilt.com/full.html? [R=302,L]
but trying this just gives http://thedutchtilt.com/?_escaped_fragment_=stories/component_74511, which is my homepage.
I'm really confused now, and nothing seems to be working (sigh).
Kartik
Current .htaccess:
RewriteEngine on
RewriteOptions inherit
# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
RedirectMatch ^/$ /index.html
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=stories/component_74511
RewriteRule ^$ thedutchtilt.com/full.html? [R=302,L]
Thanks for providing .htaccess code. Problem is your this RedirectMatch line:
RedirectMatch ^/$ /index.html
Comment it out and try again. index.html should be loaded as default using this DirectoryIndex directive:
DirectoryIndex index.html
i am doing subdomain redirection with;
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
RewriteCond %1 !^(www|ftp|mail)$ [NC]
RewriteRule ^.*$ file.php?id=%1 [L]
This turns someid.domain.com to www.domain.com/file.php?id=someid
Everything is ok for now but i am having problem to use AJAX on the page which is posting variables to a file with
$.post('post.php', {ID: ID},
As you know AJAX wont let to use like www.domain.com/post.php but when i write post.php bec. of redirection it searches for someid.domain.com/post.php
This is what i want;
1- Redirect someid.domain.com to www.domain.com/file.php?id=someid
2- Redirect someid.domain.com/post.php to www.domain.com/post.php
Change your RewriteRule line to:
RewriteRule ^/?$ file.php?id=%1 [L]
This way, only requests for / get rewritten to the file.php script, and not everything.
I'm pretty new to mod-rewrites, and I'm having trouble getting this right:
I'd like http://myurl.com/special and http://www.myurl.com/special to both redirect to http://myurl/index.php/special without changing the url for the visitor in their browser.
currently, my .htaccess looks like this, to remove www from URLs
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.myurl.com [NC]
RewriteRule ^(.*)$ http://myurl.com/$1 [L,R=301]
</IfModule>
I tried a bunch of different things to redirect the special URL, but nothing has worked for me so far, each with a different undesirable result. Please let me know if you have an idea about what I can add here!
I tried this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^special$ /index.php/special$1 [NC]
RewriteCond %{HTTP_HOST} ^www.myurl.com [NC]
RewriteRule ^(.*)$ http://myurl.com/$1 [R=301]
</IfModule>
That makes http://myurl.com/special redirect to the default controller, and makes http://www.myurl.com/special redirect to http://myurl.com/index.php/special AND changes the url in the browser. Neither of those is quite right, although the second is closer to what I need.
oh no you don't need htaccess to do that just use CI's routes. Here first change your HTACESS to this:
# Customized error messages.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
This one is way way better and you never have to change it for anything not for img folders or anything just leave it pure. now for your issue.
open routes php in the Application->config folder.
Now in CI all files route through index.php by default so i am assuming you mean your default controller anyway to route "controllers" like in your case special back to the main site just do this:
if your default controller is still "welcome" as it is downloaded you would write a route like this:
$route['special/(:any)'] = "welcome";
your url will not change and everything will be perfect
BUT DONT STOP READING YET, JUST TO MAKE SURE.
this is what your routes would look like after your done:
//these two are for CI
$route['default_controller'] = "welcome";
$route['scaffolding_trigger'] = "";
//this is your route sending all and any traffic for special
//no matter how many levels it will always go to welcome->index.
$route['special/(:any)'] = "welcome";
//if you want to use sub-pages or other functions within your welcome controller
//i.e. welcome->signup. then just send the route information to the controller like this:
$route['special/(:any)'] = "welcome/$1";
The routing class in php is very powerful and this is just a piece here for more detailed info on routing see this page:
CodeIgniter User Guide -> URI Routing
Really hope i haven't confused you more. Good Luck
Assuming www.myurl.com and myurl.com are both set-up as ServerAliases in your VirutalHost, then something as simple as...
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I have a search form and when I make a search I get this URL "http://****/video/view/search/?imeto_tam=tarsene" but I want to replace this the "?imeto_tam=tarsene" with the word I search for and my address to look like this - "http://****/video/view/search/tarsene". Generally I use mod_rewrite on my site and it's working for my links but it's not working for the form-s. Could someone tell me how to do it?
RewriteEngine On
RewriteRule ^view/([0-9a-zA-Z\-\(\)]+)/?$ index.php?a=$1 [L]
RewriteRule ^view/([0-9a-zA-Z\-():]+)/([0-9a-zA-Z\-():\.,]+)$ index.php?a=$1&id=$2 [L]
These rules would go into your root .htaccess file and 301 redirect the querystring imeto_tam to the folder and then the next rule would make it get passed to your code (index.php)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?imeto_tam=([^&]+)(&.*)?$ [NC]
RewriteRule ^video/view/search/(index\.php)?$ /video/view/search/%2/? [R=301,L]
RewriteRule ^video/view/search/([^/]+)/$ /video/view/search/index\.php?imeto_tam=$1 [L]