Forum Moderators: phranque
I am new to mod_rewrite. So I found it very confusing to deal with it.
I am dealing with a query string. and I want my url look like this
[localhost...]
and main url is,
[localhost...]
and I write something like this to be done,
Options +MultiViews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^leasing/company/(.*)/(.*)-(.*)\.htm$ leasing-company.php?postCodeArea=$1&Search_btn=$2 [NC,L]
This rule is not working for me.
Please help me, if I miss something.
Thanks in advance.
Options +ExecCGI
AddHandler cgi-script .
ErrorDocument 404 /error.php
RewriteEngine On
RewriteBase /
RewriteRule ^index.htm$ abc/index.php
RewriteRule ^(.*)\.htm$ abc/$1.php [nc]
RewriteRule ^.htaccess$ - [F]
Options +MultiViews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
I have tried this one too;
RewriteRule ^/(.*)/leasing/company/postCodeArea(.*)/btn(.*)\.htm$ /abc/leasing-company.php?postCodeArea=$1&Search_btn=$2 [L]
The main point is that you need to use the new format URLs in the links on your pages. The rewrite can only happen if someone requests the new format URLs from your server.
Don't use multiple (.*) patterns in your rule [google.com...] . It is very inefficient, as it requires multiple (maybe hundreds) backup and retry operations before a match is found. Use a pattern like
([^/]+) instead. Make sure that the value for $3 is also passed to your script and is verified as being valid. Return a 404 status if it is not.
I would not use "index.<anything>" in your URLs. I would place a redirect ahead of all the rewrites that strips the filename off (and forces www at the same time). I would internally link to URLs that end with slash. I would use a rewrite from ^$ to abc/index.php too.
.
Be aware that the (.*) in this rule matches "everything" so your other rule can never run if it is placed after this one:
RewriteRule ^(.*)\.htm$ abc/$1.php [nc] I write the rule once again;
like
rewriterule ^/(.*)/leasing/company/([^/]+)/([^/]+)/?$\.htm /leasing-company.php?postCodeArea=$1&Search_btn=$2 [L]
but still I cannot get proper result.
I have one page named as left.php, in this page I have combobox and one search button.
when enyone select something in combobox and press button search then by 'GET' method it redirect to leasing-company.php by the action tag of the form method.
code of Left.php
<form id="search" name="search" method="get" action="leasing-company.htm" >
<select name="postCodeArea" style="font-size:12px; width:175px;">
<option value="">-- select postcode --</option>
<?php
$postCode = "SELECT * FROM ukchl_postcode ORDER BY full_name";
$postCodeResult = mysql_query($postCode) or die(mysql_error());
while($postCodeArr = mysql_fetch_array($postCodeResult)){ ?>
<option value="<? echo $postCodeArr['short_name'] ; ?>" <? if ($postCodeArr['short_name']==$_REQUEST['postCodeArea']){echo "selected"; } ?> ><? echo $postCodeArr['short_name']."-".$postCodeArr['full_name']; ?> </option>
<?}
?>
</select>
<br /><br />
<input type="submit" name="Search_btn" id="Search_btn" value="Submit" />
</form>
It generates dynamically then how can I manage that url?
Help needed.
RewriteRule ^(.*)\.htm$ abc/$1.php [nc] And, again, your (.*) pattern can likely be replaced with something more efficient in all of your rules. You missed some.
Can you make me clear with dynamic url?
If I get one page with dynamic url, then how can I get my "RewriteRule"'s url.
RewriteRule old.htm new.htm
This works fine with static links, for them I can manually write that "old.htm" in page.
But
How I manage this in dynamic generated pages?
Please help me.
[localhost...]
This will generate dynamically.
For this I have to write the .htaccess file and I wrote like this,
Options +ExecCGI
AddHandler cgi-script .
ErrorDocument 404 /error.phpRewriteEngine On
RewriteBase /
RewriteRule ^index.htm$ abc/index.php
RewriteRule ^(.*)\.htm$ abc/$1.php [nc]
RewriteRule ^.htaccess$ - [F]
Options +MultiViews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /leasing-company\.php\?postCodeArea=([^&]+)&Search_btn=([^&]+)\ HTTP/
RewriteRule ^leasing-company\.htm$ http://localhost/abc/leasing-company/%1/%2? [R=301,L]
Please kindly tell me where I go wrong in it?
I will be thankful to you.
Thanks in advance.
Welcome to WebmasterWorld!
I need to make you aware of a couple of things, one administrative and the other technical.
First, we have a relatively small number of contributors here, scattered all across the world. Please do not expect "instant" responses; Some are asleep when you get to work, while others are heading home for dinner.
Second, mod_rewrite cannot change the links on your pages. It has no effect whatsoever on your page content. Mod_rewrite works after a link on your page is clicked and the client (browser) sends a request for the linked URL to your server. After this request arrives at your server, mod_rewrite examines it and can either generate a client redirect (asking the browser to request a different URL), or it can modify the server filepath that will be used to serve content for the original client-requested URL -- for example, forwarding requests for HTML pages to a script instead of simply serving a static HTML page.
As a result, if you wish to modify the linked URLs on your pages, you will have to edit your static HTML pages, or modify the script(s) that produces your HTML pages dynamically.
Your RewriteRules look quite correct, but I think you are expecting them to do something that they cannot do.
See the threads in our Apache Forum Library for more information.
Jim