Hi I am trying to change my url using htaccess but it didn't work anymore.
http://localhost:8888/cPanel/abc?page=general-settings
RewriteRule ^cPanel/([\w-]+)/?$ abc.php?page=$1 [L,QSA]
What i am doing wrong anyone can help me here please ?
I want to change the url like this:
http://localhost:8888/cPanel/general-settings
<?php
$page ='';
if($_GET['page']){
$page = $_GET['page'];
if($page == 'general-settings'){
include "/pages/general-settings.php" ;
}
}
?>
The error stands in the rule. Your actual rule is:
RewriteRule ^cPanel/([\w-]+)/?$ abc.php?page=$1 [L,QSA]
which is missing cPanel, if you want to achieve http://localhost:8888/cPanel/general-settings as result
With this rule (which means: when you Apache match cPanel/*anything*, hit the resource at cPanel/abc.php?page=*anything*) it should work:
RewriteRule ^cPanel/(.*)$ cPanel/abc.php?page=$1 [L,QSA]
Test this code
RewriteEngine on
Options +FollowSymlinks
RewriteRule ^cPanel/(.+)/?$ abc.php?page=$1
url: http://localhost:8888/cPanel/general-settings
Related
First of all: If you have a better title for this question let me know.
Hello , I have a site which loads content using get variable.
Let me explain it to you.
My index php file:
<?php
#check if get parameter page exists
#check if file exists
require $_GET['page] . '.php'; //if it exists require its content
?>
In that way users may go to my site and write urls like these ones below:
http://localhost/loremipsum?page=home
http://localhost/loremipsum?page=help
But to get a cleaner url I edited my .htaccess file to get urls like these ones:
http://localhost/loremipsum/home
http://localhost/loremipsum/help
The .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /loremipsum/?pg=$1 [L]
But I got to a point where I need other parameters, For the next url I would like to have userpreferences as the page parameter and something as the fav parameter
A url like this would work:
http://localhost/loremipsum/userpreferences&fav=something
But the goal is to get a url like this:
http://localhost/loremipsum/userpreferences/something
The problem is that nothing that I have tried have worked, This is what I thought it should work but it didn't:
RewriteRule ^(.*)/userpreferences/(a-zA-Z0-9)+ /loremipsum/?pg=$1&fav=$2 [L]
UPDATE:
I know this rule should be applied only if page parameter is equal to userpreferences and I was thinking about doing
RewriteRule ^userpreferences/(a-zA-Z0-9)+ /loremipsum/?pg=userpreferences&fav=$1 [L]
But it won't work, it seems as userpreferences would not be a string and I get a server error.
You can make a rewrite rule like so:
RewriteRule ^(.*)$ index.php?parameter=$1 [NC]
and then you get :
index.php?parameter=param/value/param/value
From the Browser you get :
http://localhost/parameter/param/value/param/value
Inside PHP file you could access your parameter:
<?php
$parameter = explode( "/", $_GET['parameter'] );
for($i = 0; $i < count($parameter); $i+=2) {
echo $parameter[$i] ." has value: ". $parameter[$i+1] ."<br />";
}
?>
I am using htaccess to generate the following url
http:/localhost/classifieds/9/my-classified-title-goes-here
using
RewriteRule ^aggelies/([0-9]+)/(.*)$ aggelies.php?id=$1&category=$2 [NC]
But in the specific page i also need to have pagination in the form of
http:/localhost/9/classifieds/my-classified-title-goes-here/?page=2
but when i cannot pass the page number in the code.
$page_number = (isset($_GET['page']))? $_GET['page'] : '1';
echo $page_number;
seems to not work
You need to use the QSA (QueryStringAppend) flag
RewriteRule ^aggelies/([0-9]+)/(.*)$ aggelies.php?id=$1&category=$2 [NC,QSA]
Solved!
first of all, I know I can use "?page=..." but I do not like that variable in my URL. Now after some searching I found a site which uses the $_GET['page'] without showing the "?page=" in the url.
But I'm having a bit of a struggle with the code. I cannot seem to get this code to work. I know it works on an other site, but not on my site. I cannot seem to find how it works on the other site.
this is the menu code:
<li>Home</li>
<li>Even voorstellen</li>
<li>De kennismaking</li>
and this is the php code:
$sExpressie = "(http:|ftp:|shttp:|www.|.php|.pl|.cgi|.asp|index.php)";
if(isset($_GET['pagina']) && eregi($sExpressie,$_GET['pagina']))
{
include("pages/home.php");
}
else
{
if(isset($_GET['pagina']) && file_exists('Pages/' . $_GET['pagina'] . ".php"))
{
include('pages/' . $_GET['pagina'] . ".php");
}
else
{
include("pages/home.php");
}
}
I don't understand how this code works. In my website the "$GET['pagina']" is never filled, which is logical. But how can it be filled in the other website?
Thanks a lot everyone!
Solution:
Add the following to your .htaccess file:
RewriteEngine On
RewriteRule ^([A-Za-z0-9-]+)/?$ pages/$1.php [NC,L]
You'll need to add the following to your .htaccess file:
RewriteEngine On
RewriteRule ^([A-Za-z0-9-]+)/?$ pages/$1.php [NC,L]
For example, if you now navigate to http://yourwebsite.com/fubar, your website will load the page located at pages/fubar.php without changing the URL.
You can use a RewriteRule within your .htaccess file.
For example:
RewriteEngine On
RewriteRule ^/(.*)$ index.php?pagina=$1 [L, QSA] #(.*) is lazy and you may want to just catch [a-z0-9].
This will "rewrite" a request like http://example.com/?pagina=even_voorstellen into something like http://example.com/even_voorstellen. Your index.php can then use $_GET['pagina'] to call the respective page.
returning html codes from ajax post process
javascript side
$('#bgn').live('click',function(){
var d = {islem:'bugun'};
$.post('inc/ajax.php',d,function(v){
$('#sol').text(v);
});
});
php side
<?
include "connect.php";
session_start();
if($_POST['islem']=='bugun')
{
echo 'furkan<br>furkanfurkan<br>furkan<br>furkan<br>furkanfurkan
<br>furkan<br>furkan<br>furkan';
}
?>
dont write into the #sol div "furkanfurkan"
returned html codes to #sol div
coming data is "...."
why?
if i don't use .htaccess this problem is solved
but i should use .htacess
please help me
sorry for my bad english
thanks for answers, i edit for var d = {islem:'bugun'};
i was edited this line but don't solved my problem
this my .htaccess page
RewriteEngine On
RewriteRule ^baslik/(.*)/$ baslik.php?id=$1&s=1
RewriteRule ^baslik/(.*)/(.*)$ baslik.php?id=$1&s=$2
RewriteRule ^kayit$ index.php?islem=yazarol
RewriteRule ^giris$ index.php?islem=giris
RewriteRule ^hakkinda$ index.php?islem=credits
RewriteRule ^istatistik$ index.php?islem=stat
RewriteRule ^mesajlar$ inc/mesaj.php
RewriteRule ^mesajlar/(.*)$ inc/mesaj.php?to=$1
RewriteRule ^yonetim-paneli$ adm.php
RewriteRule ^panel$ inc/panel.php
RewriteRule ^cikis$ index.php?islem=logoff
RewriteRule ^linkolustur/(.*)$ inc/paylas.php?id=$1
RewriteRule ^profil/(.*)$ inc/profil.php?id=$1
RewriteRule ^entry/(.*)$ inc/entry.php?id=$1
RewriteRule ^kimleronline$ inc/online.php
RewriteRule ^nick_to_mail$ index.php?islem=mail_bul
RewriteRule ^yazaramsj/(.*)$ inc/to.php?to=$1
RewriteCond %{HTTP_HOST} ^www.sozluksau\.com [NC]
RewriteRule ^(.*)$ http://sozluksau.com/$1 [L,R=301]
ErrorDocument 404 /index.php?islem=sayfayok
SOLVED :) thanks #dianuj
changed this
first add this line to .htaccess
RewriteRule ^call_my_ajax$ inc/ajax.php
and after change this
$.post('http://mysite.com/call_my_ajax',d,function(){)
You have to get the post value by $_POST['p'] because you have made your data string to send by var d = {p:'bugun'}; and getting post variable by $_POST['islem'] which is wrong
<?
include "connect.php";
session_start();
if($_POST['p']=='bugun')
{
echo 'furkan<br>furkanfurkan<br>furkan<br>furkan<br>furkanfurkan
<br>furkan<br>furkan<br>furkan';
}
?>
And change the text() to html()
$('#sol').html(v);
Edit
Change your ajax url to something and add one new rule in .htaccess
$.post('call_my_ajax',d,function(v){
$('#sol').text(v);
});
in .htaccess
RewriteRule ^call_my_ajax$ inc/ajax.php
I'm afraid some of your English is not very clear. But as I understand your code works if you don't have an .htaccess file but breaks when you do have this file.
So I would guess your .htaccess file is causing the problem. What I would do in your situation is:
Install the program Fiddler2 and get it running (this lets you see the contents of all the requests and responses to your webserver).
Try using your website with and without the .htaccess file and look at what the responses look like for ajax calls to .../inc/ajax.php. I think you might find a helpful error message there.
I want:
sub.domain.com to load index.php
sub.domain.com?s=custom to load /custom/index.php
I'm doing this right now:
In .htaccess:
RewriteRule ^(custom)/?$ index.php?subject=$1
and in index.php I have this:
if($_GET['s'] == 'custom') {
header( 'Location: http://sub.domain.com/custom/index.php' ) ;
}
... but is it possible to do the redirect via htaccess itself depending on the GET variable?
Thanks!
Yes, you could check query string with RewriteCond
RewriteCond %{QUERY_STRING} s=custom
RewriteRule ^(.*?)$ custom/index.php [L]
With this, it redirects all requests with existing "custom" get parameter to index.php, and this can be extended :)
Idea: http://statichtml.com/2010/mod-rewrite-baseon-on-query-string.html
You probably want to use "RedirectMatch"
RedirectMatch ^sub.domain.com?s=custom$ /custom/index.php
Maybe youll need to play with the regex abit