I am trying to make clean URLs at my website which i am working on local.
I am using WampServer.
Here is my .htaccess content
RewriteEngine on
RewriteRule ^search/([0-9a-zA-Z]+) search.php?semt=$1 [NC,L]
Here is what i am doing at search.php file.
<?php
if(!isset($_GET["semt"]) || empty($_GET["semt"])){
header("Location: index.php");}
else{
$region = $_GET["semt"];
include('database/config.php');
include('includes/header.php');}
?>
When i am typing,
localhost/project/search.php?semt=xxx
it is quite working.
When i am typing,
localhost/project/search/xxx
it is not working. Browser giving this error.
error screen capture
This page isn’t working
localhost redirected you too many times.
Try clearing your cookies.
ERR_TOO_MANY_REDIRECTS
Final version of the link is that.
localhost/project/search/index.php
How can i solve this problem?
You should see why this is happening from your final url. Change redirect to /index.php.
Related
I have redirected one of my redesigned website using this code.
Redirect 301 /oldurl http://www.domain.com/newurl
When I Used this code in my htaccess file. the Url I am getting is htt://www domain com/newurl?oldurl
Can any one help me regarding this
Hey some one help facing the same issue again for this website: http://www.godsfood.in/
I got this solution .Try this
RewriteRule ^old-location/?$ /new-location/ [END,R=301]
I'm new at Code Igniter. My index page is named abc_welcome where i've below code
public function index()
{
$this->load->library('session');
$login_data = $this->session->userdata('user');
if($login_data) {
redirect('/product/product_details');
}
else {
$this->display();
}
}
So when a already logged in user hit he can redirect to product page. But strangely it is not redirecting.
Where as at login page i've same piece of code and it is redirecting all right.
So when a user come to my www.abc.com page it's not redirecting (if loged in) and session has no data checked but when cliking login button he is and obviously session got the right data. i want him to redirect first time.... more strangely in my demo site (my laptop) Index redirecting is working!!! but not at hostgator.com.
Thanks in advance.
Farness
Thank you all for your support.
i finally made it work by .htaccess redirecting. i just put below code to my .htaccess and it's working as expected.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.abc.com [NC]
RewriteRule ^(.*)$ http://abc.com/$1 [L,R=301]
yes #farness put $config['base_url'] = 'http://www.abc.com/'; in your config.php file
From what you're describing, it seems like your code is fine, if it runs locally on your laptop, so it's likely that the session data isn't being stored/read properly. Aside from the base_url above, you should also verify the following settings in /appication/config.php:
$config['cookie_domain'] should be set to .abc.com (with the leading dot) if your base url is www.abc.com
$config['cookie_path'] just to be safe, set this to "/"
$config['cookie_secure'] set to FALSE (unless your site is accessed only using https, keep this as false
Hopefully that gets you up and running.
the problem is that for some reason googlebot gets a bunch of error 404s when crawling a certain page but everything works fine on my end, I think...
using htaccess, I have rewritten a page with vars for seo purposes, so:
RewriteRule ^feeds/([^/]*)\.xml/?$ /rss/feeds.php?cat=$1 [QSA,NC,L]
so I get www.url.com/feeds/category.xml
instead of
www.url.com/feeds.php?cat=category
I've also ajusted all urls on the page to follow this rule and like I said everything works fine on my end... googlebot for some reason only sees www.url.com/feeds/category and does see the .xml extention.
not sure if it would work but I was hoping to put a rule in htaccess to redirect www.url.com/feeds/category to www.url.com/feeds/category.xml in the even that this happened, but was unsure of how to do so.
Maybe try
RewriteRule ^feeds/([^/]+)/?$ /feeds/$1.xml [R,NC]
Which would redirect www.url.com/feeds/category to www.url.com/feeds/category.xml, using a HTTP 302 Redirect. Remove the R flag if you don't want it do use the HTTP 302 Redirect, but that would make www.url.com/feeds/category a valid URL as far as google is concerned. Just in case: mod_rewrite.
I am trying to create a login page for some sites that I manage. So far it worked easy enough by having a login page which connects to a database which told the page where to redirect them.
I also have an .htaccess that rewrites the URL to pass through an authorisation page that just checks if a session has been started then pushes them through.
The problem I have is that when an admin logs in to the admin page it isn't parsing the php and when I go 'view source' I can see all the code... how do I get it to parse the php?
.htaccess
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ ../authorise.php?file=$1 [NC]
authorise.php
session_name('TSiteStats');
session_start();
if (isset($_SESSION['user_id'])) readfile ($_SESSION['redirect'] . '/' . $_REQUEST['file']);
else header("Location: ../login.php");
Just to be sure.
Does you file use the <?php and ?> tags. These tag will tell Apache to load the PHP code to be executed.
Also, does the script can be executed (has the authorization to be executed by Apache).
Last thing, your code is using readfile which output the content of the file and not execute this one. Are you sure you want to readfile and not include it?
Everything was working fine till I added my .htaccess file. What I'm trying to do is route all my users to their profile page. So www.darudude.com/user1 routes to www.darudude.com/userinfo.php?user=user1
My .htaccess file as this:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ userinfo.php?user=$1 [L,QSA]
However ever since I added this, it breaks my sessions. On every page I have a initialize a session, and the sessions stores the referrer. This is the piece of code that handles the important part.
if(isset($_SESSION['url'])){
$this->referrer = $_SESSION['url'];
}else{
$this->referrer = "/index.php";
}
//this echo is used to debug why this thing isn't working!!
echo "<script>alert('".$this->referrer."');</script>";
/* Set current url */
$this->url = $_SESSION['url'] = $_SERVER['PHP_SELF'];
and then I'm returned to the original page using this piece of code:
header("Location: ".$session->referrer);
So for example, without the .htaccess file, if I login through one of the pages everything works and I get redirected back to the page I logged in from (i.e. if I logged in from index.php I get redirected back to index.php; if faq.php, I get redirected back to faq.php). With the .htaccess file I keep getting sent to /userinfo.php leading me to thing its something wrong with my rewriterule
This is how its supposed to work:
index.php loads. the $_SESSION['url'] is set to index.php
a login form is enacted whos action redirects to process.php
process.php the $session->referrer is set from $_SESSION['url']
After the login is confirmed the page should redirect using: header("Location: ".$session->referrer);
This is how it worked originally without any problems.
However, after the .htaccess was created it seems to redirect me to userinfo.php. I think it has something to do with my rule.
Any ideas?
I'm not sure if I understand the problem, but the rewrite rule you're using seems to turn the request to /index.php into a request to /userinfo.php?user=/index.php which may not be what you want.
It's because you're relying on $_SERVER['PHP_SELF'], which does not include the query string (the ?user= part of the URI). It worked before because your pages didn't rely on query strings to uniquely identify themselves. You can use $_SERVER['REQUEST_URI'] instead, though look out for circumstances where you don't want the query string to be preserved and now it is being.
Incidentally, the \?* in your RewriteRule regex is doing exactly the same as thing as if it weren't there.
You could try logging in with AJAX, thus never having to refresh the page at all. A simple Google search will throw up plenty of results, see below. Even if you're not using jQuery (which alot of the tutorials seem to expect you to), it's still possible with basic Javascript, in fact that's how I wrote my AJAX log-in script before converting it to use jQuery later.
http://www.google.com/search?q=php+ajax+log-in