Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: *Fixed* Needing help with confusing .htaccess problem |
|
Author |
|
jimmasami
Joined: 30 Apr 2013 Posts: 3 Location: UK
|
Posted: Wed 01 May '13 11:18 Post subject: *Fixed* Needing help with confusing .htaccess problem |
|
|
I'm hoping someone here can help with this. I've been working at this for days and can't get any further forward. Maybe it's so obvious I just can't see it.
I need to implement a proper url structure from my php pages but I keep getting duplications in the url string. I finally set up a couple of simple pages and a very simple .htaccess file. But still nothing works. I've even installed apache 2.2.22 in case it was a problem with 2.2.
Options +FollowSymLinks
RewriteEngine on
rewritecond %{http_host} ^localhost
RewriteRule ^category/item1$ url1.htm [DPI,L]
Clicking <a href="category/item1">Test1</a> the first time produces the correct result - http://localhost/category/item1 but clicking a second time produces http://localhost/category/category/item1
I've tried every combination possible plus all the sample rewriterules - all have the same problem.
I've been through every forum I can find but I can't find a resolution.
Last edited by jimmasami on Thu 02 May '13 15:04; edited 1 time in total |
|
Back to top |
|
Steffen Moderator
Joined: 15 Oct 2005 Posts: 3118 Location: Hilversum, NL, EU
|
Posted: Wed 01 May '13 20:52 Post subject: |
|
|
Not sure what you want to achieve.
Did you play with the following ?
RewriteRule /category/item1(.*) url1.htm [L] |
|
Back to top |
|
jimmasami
Joined: 30 Apr 2013 Posts: 3 Location: UK
|
Posted: Wed 01 May '13 23:44 Post subject: |
|
|
Hi Steffen, many thanks for the reply. ATM I'm just trying to figure out the basics before I can start on the main site. I did initially try it with the development php pages and kept hitting the same problem so I set up a small test with the bare minimum to try and solve the problem.
The problem is that category/ keeps getting added to the friendly url. By clicking the link (<a href="/category/item1">Test1</a>) a few times you eventually get something like this:-http://localhost/category/category/category/item1 and then clicking a href="/testurl.htm">Main</a> you end up with this:http://localhost/category/testurl.htm in the url and a 404 error.
I just need to know why "category" is being duplicated in the url. I've just tried your suggestion but same result.
I'm hoping someone can shed some light on this soon as it's driving me insane. |
|
Back to top |
|
jimmasami
Joined: 30 Apr 2013 Posts: 3 Location: UK
|
Posted: Thu 02 May '13 13:37 Post subject: Finally Working |
|
|
Options +FollowSymLinks -Indexes
RewriteEngine on
rewritecond %{http_host} ^/localhost
# If it's a request for a directory, add the trailing slash.
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule category/item1(.*) url1.htm [L]
After trying almost every combination possible I've finally managed to get the damned thing working. Seems to be using the leading slash in %{http_host} did the trick.
Thanks for your help Steffen, using your code highlighted the fact that it was probably in the directory slashes somewhere. Greatly appreciated now I have to get on and rewrite the live site - happy days.  |
|
Back to top |
|
|
|
|
|
|