I use htaccess to rewrite my URL's so here is what I have:
RewriteRule ^([^-]+),([a-z0-9._.-]+),([^-]+) index.php?go=$1&lang=$2 [L]
and code PHP:
function rewrite_seo($id, $title, $langs) {
global $core;
if($core->getSettings('seof')) {
$result = $id.','.$langs.','.changeSigns($title).'';
} else $result = '?go='.$id.'&lang='.$langs;
return $result;
}
My URLs look like:
http://localhost/script/12,en,home
but want to look like this:
http://localhost/script/en/home,12
how to modify this code?
localhost/script/12,en,home TO
localhost/script/en/home,12
Did u try to modify line 4?
Put that:
$result = $langs.'/'.changeSigns($title).','.$id;
Please take a look to PHP.net webpage http://php.net/manual/de/internals2.opcodes.concat.php
You have to change the links written in PHP as pointed out in the previous answer :
$result = $langs.'/'.changeSigns($title).','.$id;
And then change the matching rule in your htaccess :
RewriteRule ^([a-z0-9._.-]+)\/([^-]+),([^-]+) index.php?go=$2&lang=$1 [L]
Even better, you can make more specific capture regex, so it would be easier to read and understand :
RewriteRule ^([a-z]+)\/([0-9]+),([^-]+) index.php?go=$2&lang=$1 [L]
Related
Following URL should be redirected:
abc-deut.html -> de/abc
abc-eng.html -> en/abc
Where deut = de
And eng = en
I am looking for something like:
RewriteRule ^abc-(deut|eng).html (de|en)/abc [R=301,L]
Does this work with htaccess?
You can use this rule:
RewriteRule ^([\w-]+)-(en|de).*\.html$ /$2/$1 [R=301,L,NE,NC]
I have this rules in my .htaccess
RewriteRule ^clothes/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ products.php?g=$1&$2=$3&$4=$5&$6=$7&$8=$9&$10=$11 [L]
RewriteRule ^clothes/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ products.php?g=$1&$2=$3&$4=$5&$6=$7&$8=$9 [L]
RewriteRule ^clothes/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ products.php?g=$1&$2=$3&$4=$5&$6=$7 [L]
RewriteRule ^clothes/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ products.php?g=$1&$2=$3&$4=$5 [L]
RewriteRule ^clothes/([^/]+)/([^/]+)/([^/]+)/?$ products.php?g=$1&$2=$3 [L]
RewriteRule ^clothes/([^/]+)/?$ products.php?g=$1 [L]
which can be something like website.com/clothes/women/type/tshirts/brand/nike/color/red/size/s/price/0-29
and this should be the print_r($_GET)
Array
(
[g] => women
[type] => tshirts
[color] => red
[brand] => nike
[size] => s
[prezzo] => 0-29
)
So starting from website.com/clothes/women/ I can then add filter/value pairs and arrive at the point where I can have that big url with all the possible filters.
The problem is that the last filter/value pair is not working, this snippet from the first rule in .htaccess [..]&$10=$11. So instead of the aspected dumped data, I get this
Array
(
[g] => women
[type] => tshirts
[color] => red
[brand] => nike
[size] => s
[women0] => women1
)
So basically it replaces the last filter/value pair with the name of the first filter, g=$1.
Is there a limit withing .htaccess of how many parameters I can pass into the url ? It seems to me that the last parameter is $9, so $10 is not taken into consideration.
If that is the case, can I fix this problem ?
Thank you.
You can overcome this mod_rewrite by having this recursive rule. Place this in root .htaccess:
RewriteEngine On
RewriteBase /
RewriteRule ^(clothes/[^/]+)/([^/]+)/([^/]*)(/.*)?$ $1/$4?$2=$3 [L,QSA,NC]
RewriteRule ^clothes/([^/]+)/?$ products.php?g=$1 [L,QSA,NC]
I seem to have problem with an .htaccess rewriterule.
What I want to do is a dispatcher of this form:
[website]/[parameter1-text]/[parameter2-text]
I have in my .htaccess the following:
RewriteRule ^(.*)/(.*)$ dispatcher.php?s1=$1&s2=$2
So far so good. But s1 and s2 are some variables that need to be matched in a database (mysql) and return the true variables that feed the script view.php in the following format:
view.php?category=[s1]&subcategory=[s2]&objects=5
How can I redirect this properly using header("Location: /view.php[...]"); and having the url unchanged (for example: http://example.com/CARS/BLUE http://example.com/SLIPPERS/RED/ )
First of all fix some minor issues with your .htaccess:
RewriteRule ^([^/]+)/([^/]*)/?$ dispatcher.php?s1=$1&s2=$2 [L,QSA]
Now inside dispatcher.php do your Mysql stuff and fetch values of s1 and s2 from database. Once you're done and want to internally forward your request to: view.php?category=[s1]&subcategory=[s2]&objects=5 have this type of PHP code:
$_GET['category'] = $value-of-s1-from-DB;
$_REQUEST['category'] = $_GET['category'];
$_GET['subcategory'] = $value-of-s2-from-DB;
$_REQUEST['subcategory'] = $_GET['subcategory'];
$_GET['objects'] = '5';
$_REQUEST['objects'] = $_GET['objects'];
// now include view.php
// all your parameters are available in view.php in $_GET array
require_once("view.php");
Here's part of my .htaccess file:
.htaccess:
RewriteRule ^([a-z0-9A-Z_-]+)$ /article/index.php?title=$1 [L]
But the problem is that when title is empty it doesn't show me the content of http://www.domain.com/index.php. I can't even link to http://www.domain.com/ anymore without throwing the error.
PHP: http://www.domain.com/article/index.php
<?php
if(!empty($_GET['title']))
{
$a = mysql_query("SELECT * FROM `articles` WHERE `title` = '".mysql_real_escape_string($_GET['title'])."'");
}
else
{
$a = mysql_query("SELECT * FROM `articles` WHERE `id` = '".mysql_real_escape_string($_GET['id'])."'");
}
$b = mysql_fetch_assoc($a) or mysql_error();
?>
You pretty much have 2 choices:
1. Use this rule: If home page is hit, then title parameter will be empty (so you have to handle this moment somehow -- adjust your PHP code accordingly).
RewriteRule ^([a-z0-9A-Z_-]*)$ /article/index.php?title=$1 [QSA,L]
2. Use specific rule for home page/website root hit (add it before your current rule):
RewriteRule ^$ /article/index.php?title=home [QSA,L]
The title=home means it's a hit for website root (you can change home to whatever you want).
Current URL
http://domain.com/page/2/
.htaccess
RewriteRule ^page/([0-9]+)/$ /index.php?p=$1 [L]
Next URL
http://domain.com/page/2/?by=1
How to get the by=1?
Because when I print_r($_GET) It's only display Array ( [p] => 2 )
What should I write in my .htacces to get the [by] => 1
Change the end of your line from [L] to [QSA,L] to preserve the query string.