I got an error with SEO linking..
this is what happens..
http://boznetwork.net/index.php?a=explore
If you click on a track (not the play button) but if you click on the title of the track. The orange load bar will not redirect you to the track page.
But if you open the track in a new tab then you will see the track.
What did I do wrong?
My .htacess file looks like this:
RewriteEngine on
RewriteCond %{request_filename} -f
RewriteRule ^(.*) $1 [L]
RewriteRule index/a/(.*)/id/(.*)/ index.php?a=$1&id=$2 [L]
and the links I changed it to:
<a href="'.$url.'/index/a/track/id/'.$row['track'].'/"
but before I changed the link it looked like this:
<a href="'.$url.'/index.php?a=track&id='.$row['track'].'"
Your first rule is bogus. It always matches, then rewrites to exactly the same thing. This prevents the Apache from reaching the second rule.
Remove your first rule, and everything should work as expected.
Related
What I would like is if the user enters:
www.mysite.com/test
This would redirect to a page that would search my db for an event called test and if the event exists show the event else redirect to a search page.
I've nearly managed to get this to work - so close yet so far...
This is where I've got to:
RewriteEngine On
RewriteRule ^([A-Za-z0-9-]+)/?$ show_events.php?q=$1 [NC,L]
It works in that it redirects to the show_events.php page which searches the db for an exact match and displays the event if it finds one, else it redirects to a search page. I'm very pleased with this.
The problem is when the folder (www.mysite.co.uk/test/) exists already an error page shows saying "this page isn't working". The folder just contains a HTML page that displays the word "hello". If you type www.mysite.co.uk/test/index.html the page displays ok so it's not like it isn't working.
I've concluded the search page works fine but the RewriteEngine code doesn't.
This post looked like it would solve my problem but not quite:
Apache RewriteEngine - Rewrite anything that not exists to index.php
I thought that by adding DPI on the end of the RewriteRule it might solve the problem but it doesn't.
I really don't understand RewriteEngine and am just groping around in the dark using trial and error, can someone help me?
The problem is that your rule also rewrites existent directories to the destination file. You need to put a condition to exclude directories from the rule :
RewriteEngine On
RewriteCond ℅{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-]+)/?$ show_events.php?q=$1 [NC,L]
The RewriteCondition will prevent your existent directories from being rewritten to the rule's destination url.
You can simply add a condition to avoid touching existing folders
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-]+)/?$ /show_events.php?q=$1 [NC,L]
I've had a good look through all the other htaccess url rewrite questions, but all of them deal with the reverse of my problem.
The site I am working on takes content from child pages in WordPress and presents them as anchored sections on the parent page. The problem for the site now is that if Google (or the built in search, though that can probably be done in the templates) links to one of the child pages it will direct users to the single page rather than the correct section of the parent page.
I was hoping to come up with a URL rewrite pattern which would reformat the URL to what I need, but it doesn't seem to work... and I know that's because I have done it wrong!
The URL which needs to be rewritten is something like:
website.com/parent-page/child-page/
I need this to be rewritten to:
website.com/parent-page/?subpage=child-page
My initial stab at it looks like this, but I know I've misunderstood something about how to format the pattern.
RewriteRule ^/$1?subpage=$2 ^/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/$
Can anyone help format this correctly or point out where I'm going wrong?
You can use:
RewriteEngine on
# If the request is not for a valid file/directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ /$1/?subpage=$2 [QSA,L]
No initial / in htaccess RewriteRule first uri
And optional final /
RewriteRule ^([^/]+)/([^/]+)/$ /$1/?subpage=$2 [L]
The htaccess rewrites didn't seem to work, so I've created a PHP redirect instead by taking the page slug, page parent permalink and mashing the two together.
Not the most elegant solution, I expect, but it works.
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|zip|scripts|uploads|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]
This is the site
Notice, every link you click, the change is done in the address bar, but not on the page.
Whats the problem with this HTACCESS code?
Thnx in advance :-)
Your .htaccess code is right for what it meant to do.
Appending index.php internally so you have a cleaner url in your browser address bar. Be clear on your question.
What you meant by "every link you click, the change is done in the address bar, but not on the page" ?
I recently with the help of SO solved my htaccess rewriterule issue:
Reuse subdomain in a rewrite rule
The result is that when somebody enters
whatever.example.com/anypage
in the adress bar, the htaccess automatically redirects to
whatever.example.com/somepath/whatever/anypage
What I wish to do is to find a way to just show whatever.example.com/anypage in the adress bar with the content of whatever.example.com/somepath/whatever/anypage displayed.
In the post I mentioned earlier, Jon Lin clearly mentions the following:
redirects always change what's in the browser's URL address bar
However I know some very frequent cases of url rewritting that would show in the adress bar let's say, for instance:
example.com/article-1-15
but actually showing the content of
example.com/somepath/somepage.php?article=1&otherparam=15
How could this apply to my case? I really wish to have a tiny url but it seems I missed something.
You may try something like this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/([^/]+)$
RewriteRule .* http://whatever.example.com/somepath/whatever/%1 [L]
It will map:
http://whatever.example.com/anypage
To a resource at:
http://whatever.example.com/somepath/whatever/anypage
showing always in the browser's address bar:
http://whatever.example.com/anypage
UPDATED
If whatever is dynamic and is the same in the substitution URI, here is another option:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ([^/]+)\.example\.com.*
RewriteCond %{REQUEST_URI} ^/([^/]+)$
RewriteRule .* http://%1.example.com/somepath/%1/%2 [L]
This will work as long as both "whatever" in the substitution path are the same. If they are not, the last "whatever" has to be hardcoded, like this:
RewriteRule .* http://%1.example.com/somepath/whatever/%2 [L]
There is no other way as the incoming URL doesn't have it.
Hi I have a basic .htaccess file in a subdirectory folder called 'support' which looks like this:
RewriteEngine on
RewriteRule ^knowledgebase/([^/]*) knowledgebase.php?article=$1 [NC,L]
RewriteRule ^knowledgebase/category/([^/]*) knowledgebase.php?category=$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
I have changed the links in my files and removed the .php extension. When I click on a link to the rewritten url to my knowledgebase file everything works fine however I then have further links to the same file with query strings in the url eg:
$link = 'knowledgebase/category/'.$article['catid'];
The problem is once I am on the knowledgebase page links appear as:
http://www.example.com/support/knowledgebase/knowledgebase/category/2
I am pretty sure I need to use a RewriteCond to stop it rewriting but I can't figure out exactly what is required.
Any help would be appreciated.
If I understand correctly, I think this is not a mod_rewrite problem, since mod_rewrite has nothing to do with what links display on the page. Rather, this looks like an issue with the hrefs that are actually in your link definitions (i.e., <a> tags).
The quickest fix might be to add something like:
<base href="http://www.example.com/support/" />
within the <head> section of your pages. That way, if "knowledgebase" is specified within the links, it won't show up twice in the URL for that link.
Let me know if I have this completely wrong.