htaccess rewrite get string to integer - .htaccess

I want to receive a letter from a $_GET after making a post and rewriting an url with htaccess. For example:
$_POST['setting'] = 'w';
After a post I'm making a redirection like this:
/*more post variables here*/
$setting = $_POST['setting'];
header("Location{$basedir}page/$budget/$region/$reservations/$pool/$conference/$open/$meal/$setting/");
exit();
my htaccess configuration looks like this:
RewriteRule ^page/([0-9]+).([0-9]+)/([0-9]+).([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/[a-z]/?$ page.php?budget=$1.$2&region=$3.$4&reservations=$5&pool=$6&conference=$7&open=$8&meal=$9&setting=$10
I have tried with this too and had no luck:
RewriteRule ^page/([0-9]+).([0-9]+)/([0-9]+).([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/(.*)/?$ page.php?budget=$1.$2&region=$3.$4&reservations=$5&pool=$6&conference=$7&open=$8&meal=$9&setting=$10
After the redirection $_GET['setting'] is not a string as I expect but an integer.
URL example: server/site/page/0.0/0.0/0/1/1/0/0/w/
This is how a var_dump of $_GET looks like.
array (size=8)
'budget' => string '15.30' (length=5)
'region' => string '0.0' (length=3)
'reservations' => string '0' (length=1)
'pool' => string '1' (length=1)
'conference' => string '0' (length=1)
'open' => string '1' (length=1)
'meal' => string '0' (length=1)
'setting' => string '150' (length=3)
Any idea of what is going on here or what am I doing wrong? Thank you

There is a limit of 9 back references in mod_rewrite, I read it from here RewriteRule using $10, $11, $12, and so on so a solution could be add the next references in a variable as a string and use the php explode function to catch the results.

try like that;
RewriteRule ^page/([0-9]+).([0-9]+)/([0-9]+).([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([a-zA-Z]+)/?$ page.php?budget=$1.$2&region=$3.$4&reservations=$5&pool=$6&conference=$7&open=$8&meal=$9&setting=$1

Related

Multiple Subdomain redirect to TYPO3 and RealUrl

I have TYPO3 7.6.18 installed with realURL and two languages (en,fr) on a single tree. the installation is on subdomain fr.mysite.com with bot domains added to the root page. For both languages I need a different subdomain. On first call of en.mysite.com I need to redirect to fr.mysite.com but the URL keeps at fr.mysite.com. Clicking on a link then changes the URL correctly to en.mysite.com.
I'm aware that the following htaccess is wrong but I got no idea how it should be.
htaccess
RewriteCond %{HTTP_HOST} ^en.mysite.com$ [NC]
RewriteRule ^ http://fr.mysite.com/%{REQUEST_URI} [P]
Adding ?L=1 to the RewriteRule solves the problem on a first call and the URL ist correctly en.mysite.com but then on a second call like en.mysite.com/subsite realURL shows the postVar error.
the typoscript:
config {
sys_language_uid = 0
simulateStaticDocuments = 0
language = de
baseURL = http://fr.mysite.com/
}
[globalVar = GP:L = 1]||[globalVar = GP:L = en] || [globalString =
IENV:HTTP_HOST = en.mysite.com]
config {
sys_language_uid = 1
language = en
baseURL = http://en.mysite.com/
}
[global]
realurl_conf:
...
'preVars' =>
array (
0 => array(
'GETvar' => 'L',
'valueMap' => array(
'en' => '1'
),
'noMatch' => 'bypass'
)
),
...
Any help would be highly appreciated.
I don't think that changes in the default .htaccess are required but both domains are handled by TYPO3 and realurl.
In realurl you've to make a setup for both domains and adjust the required parameters on base of a default configuration.
In Backend you've to create the required language-records beside the setup which you posted.
Your Setup has a fault, for fr it should be like this:
config {
sys_language_uid = 0
simulateStaticDocuments = 0
language = fr
baseURL = http://fr.mysite.com/
}
EDIT: Above I assume that both domains are handled by the same TYPO3 installation. That's possible and in general a good solution.

Rewrite Query string in URL using .htaccess

How to rewrite my website's url from "website.com/example.php?site=youtube" to "website.com/example/youtube" where site is a variable?
Should i change the url in the php file too?
You can use this in your .htaccess file:
RewriteEngine On
RewriteRule ^example/([^/]*)$ /example.php?site=$1 [L]
That will leave you with the following URL: http://website.com/example/youtube. Make sure you clear your cache before you test this.
$connection = mysqli_connect("localhost" , "root" , "" , "test");
$query = "SELECT * FROM websites";
$select_all_sites = mysqli_query($connection,$query);
while ($row = mysqli_fetch_assoc($select_all_sites)) {
$site_title = $row['site_title'];
echo "<a class='item' href='site.php?website=$site_title'> $site_title</a>";
On the other page which is called site.php i am using this code to get the variable from the sites.php page
function myname(){
if(isset($_GET['website'])){
$variable = $_GET['website'];
echo $variable;
}
}

How do I fix SEO urls with lighttpd?

I want to rewrite my URL from ?p=pagename to a SEO friendly URL like this: /pagename
How does url.rewrite works?
I have seen an example like this but haven't figured how it works yet.
url.rewrite = (
"^/(data|install|js|styles)/(.*)$" => "$0",
"^/(.*\.php)(.*)$" => "$0",
"^/.*(\?.*)" => "/index.php$1",
"" => "/index.php"
)
The query string is not part of the URL matched by rewrite rules. You can match against the query string separately:
$HTTP["querystring"] =~ "^p=([^&]+)" {
url.rewrite = (
"/%1"
)
}

modrewrite for smart URL's | multiple variables?

What is the best way to accomplish that?
Im planning to do some kind of smart modrewrite + a function to grab variable name from the URL.
For example:
A URL like:
domain.com/page-blog/id-5/title-a_blog_title/date-2011_08_05
Would return:
$urlvariable = page-blog/id-5/title-a_blog_title/date-2011_08_05
Than, I will run a function that will parse the $urlvariable and return
$urlvariable['page'] = blog
$urlvariable['id'] = 5
$urlvariable['title'] = a_blog_title
$urlvariable['date'] = 2011_08_05
But the rewrite should be able to handle smaller or bigger urls like:
domain.com/page-blog/id-5/
returning:
$urlvariable = page-blog/id-5/
or also:
domain.com/page-blog/id-5/title-a_blog_title/date-2011_08_05/var1-foo/var2-bar/var3-xpto/var4-xyz etc ...
$urlvariable = page-blog/id-5/title-a_blog_title/date-2011_08_05/var1-foo/var2-bar/var3-xpto/var4-xyz
Any way to do that? What would be the expression for rewrite?
Thanks,
As for me, the best way is to route all request to your php/another_language script and then use something like this:
for($i=1,$arr=explode('/',$_SERVER['REQUEST_URI']),$s=count($arr);$i<$s;++$i){ //avoid 0(empty part) and 1(script name)
$tmp=explode(' ',$arr[$i]);
$get[$tmp[0]]=$tmp[1];
}
RiaD has the right idea, using explode rather than regexps (since regexps are slower).
However, you might want to use regular expressions anyway to "normalize" the URL. But after that you can still use explode for a tiny speed gain, or do something like this
$url = "page-blog/id-5/blank-/title-a_blog_title/date-2011_08_05/var1-foo/var2-bar/var3-xpto/var4-xyz";
$url = preg_replace("~//+~", '/', $url); // remove multiple consequtive slashes
$params = array();
if( preg_match_all("~(\w+)-([^/]*)~", $url, $params) ) {
$params = array_combine($params[1], $params[2]);
print_r($params);
}
That will print:
Array(
[page] => blog
[id] => 5
[blank] =>
[title] => a_blog_title
[date] => 2011_08_05
[var1] => foo
[var2] => bar
[var3] => xpto
[var4] => xyz
)

Part of url passed as variable in query string incorrectly includes their query string

I am in the process of moving a site to another server and I've ran into a problem.
The site uses .htaccess to redirect to index.php so the index.php can use $_SERVER['REQUEST_URI'] to load the whatever page is being called... However i cannot find where the old server has the .htaccess rules...so I am doing my own.
The .htacess rules I use are:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /index.php/?$1 [L,QSA]
the URL is newsiteurl.com/racintv/video_view?channel_id=2
and by printing out the params on the index.php page I am getting
Array ( [page] => racintv/video_view?channel_id=2 )
It should load the video_view page and pass channel_id (which loads a video playlist). This is not the case as it thinks the page to load is actually /video_view?channel_id=2
On the old site, I print out the params on the index.php page it prints
Array ( [page] => racintv/video_view )
and passes the ?channel_id=2 correctly as the video loads correctly
What am I missing in my .httacess that would pass ?channel_id=2 correctly?
Here is the PHP code which parses the URI
$path_info = trim(substr($_SERVER['REQUEST_URI'],1)) ;
$var_array = explode('/',$path_info);
$num_vars = sizeof($var_array);
if ($num_vars==1 or !($var_array[1])) {// in the form of '/foo' or '/foo/'
if ($var_array[0] && ! strstr($var_array[0],'index')) {
$var_array[1] = 'index'; // use index as the default page
$num_vars = 2;
}
}
if ($num_vars >= 2) { // in the form of '/foo1/foo2[/foo3 ...]'
$tmp_array = explode('.',$var_array[1]);
$var_array[1] = $tmp_array[0];
$page = $var_array[0] .'/'.$var_array[1];
$vars['page'] = $page;
$q_str = '';
for ($i=2;$i<$num_vars;$i++) {
$key = $var_array[$i];
$value = $var_array[++$i];
if ($key && $value) {
$vars[$key] = $value;
$q_str .= "$key=$value&";
$$key=$value;
}
}
}
//end of search engine friendly url parsing
The page parameter is missing:
RewriteRule ^(.+)$ /index.php/?page=$1 [L,QSA]

Resources