htaccess is not working properly - php

I have a problem in htaccess file when i want to write a code of url rewriting in my htaccess file. I want to change this url "quotewebster.com/topics.php?topic_id=12" into this
"quotewebster.com/topics/12/"
I write this a code in my htaccess file:
RewriteRule ^topics/([0-9]+)/?$ topics.php?topic_id=$1 [NC,L]
And it is running fine, But a problem arises when i click any topic it goes to the right page and URL also rewrite but when i want to change the topic and again click on any topic then the url previous topic id embed with the new topic id and URL is something like that
"quotewebster.com/topics/12/topics/13/"
I don't understand it why it is happening. Please help me in this case. And sorry for bad english.
Thanks

Your problem is most likely with the way you generate your urls.
Make sure that your links start with a slash:
href="/topics/12"
not
href="topics/12"

Related

Url Rewrite via.htaccess

I have a problem with Url Rewrite in my multilingual site, or better, maybe I don't understand it very well.
My original link is something like
www.mydomain.com/index.php?lang=en&s=2
I write this rule:
RewriteEngine On RewriteRule ^([^/]*)/([^/]*)\.html$ index.php?lang=$1&s=$2 [L]
and it's work. In fact if I write in the address bar
www.mydomain.com/en/2.html (smart url)
I go to the correct page with a smarter url on the address bar.
But the problem is that the link on my code is still:
link
and when I click it, the URL on the address bar is the original, not the smart one.
I thought that the rule on htaccess would have automatically "turned" (in the address bar) all my links in something smarter without changing the original php code...but maybe I'm wrong.
If I'm wrong how should I write my links in order to have smart urls but passing variables to identify languages and pages? I'm confused.
Thank you.
After rewriting URL in your .htaccess you need also to change the URL in your page for example in given link link you need to remove question mark
<a href="index.php/<?php echo $lang?>/2">

why is my htaccess adding current page url to all links on the page

Am new to htaccess rewrite rules but with some few tutorials i've been able to write some few rules but the problem now is that the rules work well but every links on the page is preceded with the current page link therefore rendering all links on the page invalid. Below is a sample code
RewriteEngine on
RewriteRule ^school/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ school.php?country=$1&school=$2 [NC,L]
For example if i access school page as school/spain/university the link to my index page which is supposed to be index would change to school/spain/universty/index
I've searched everywhere for a similar problem or solution but i didn't see any.
The best way to solve the problem is to use base link at the head of your page.
This solves the problem perfectly, it doesn't matter if you're using relative link or absolute link.

How make url from two get value and use one in urlbar by htaccess or php

I can make
post.php?post_id=1&post_url='demo-url'
to
1/demo-url
by .htaccess and this is the code of htaccess
RewriteRule ^([0-9]+)/([0-9a-zA-Z_-]+)$ post.php?post_id=$1&post_url=$2 [NC,L]
Now I want to create an url which will remove 1 or post_id from the url just show the post url like
/demo-url
I've checked all of the stackoverflow problem but can't find it. I think htaccess can create that or if that can't then tell me which will be my php code to solve that problem...
Can any one help me to solve the problem?

.htaccess and mod-rewrite for my wordpress admin panel

Any ideas on how to rewrite my admin URLS would greatly be appreciated.
I have created some menus using functions.php and they are working properly but I need a way that I can use on my .htacess to re-write my code.
The original URL is displaying like this:
http://www.website.com/wp-admin/admin.php?page=for_buyers
I want it to display like this:
http://www.website.com/wp-admin/menu-sample/submenu-sample/
Thank you!
I don't know how many pages you have to rewrite the urls for but you could do 301 redirects which be easy for a few pages but a bit dirty.. Since it sounds like you already have the new links set-up
Otherwise you need to look through their php code..
http://www.website.com/wp-admin/admin.php?page=for_buyers
Their passing info through the url to direct the user to the correct page.. So they clicked this link, and they set it up so that it goes to page=for_buyers. I would bet this code is in the admin.php, but you would most likely need to edit other php files that get redirected to this admin.php file..
I might be missing your question completely.. Let me know..
RewriteEngine on
redirect 301 /category/product-line/samplepage.htm http://websitename.com/newpage.htm
so the page you are redirecting, just take awaY the domain.com part and start with the slash, then a space, then the full html path of the page you are redirecting to.. start with one and give it a min and see if it works.. then go from there.. the htaccess file should be in your main directory.. wordpress should already have one created and you just add to the end of it..
Good luck -Pat
Go to your settings > permalinks and select Post name
Thanks.

PHP id in .htaccess

I Have a .htaccess file for a blog script which currently generates a number for a blog post based on it's ID in the MySQL database. Is there any way I can change this so that it uses something like $subject as the URL from my PHP file? I have pasted my current .htaccess code below.
RewriteEngine On
RewriteRule ^blog-([0-9]+).html$ index.php?act=blog&id=$1
I hope people can understand what I am trying to describe.
Thanks in advance.
Regards,
Callum Whyte
Using just the subject is probably a bad idea, if you ever change the title, all links to your page (from google, or elswhere) will be broken. I would include both the subject and the idea, that way you'll always be able to match an URL to a blog post:
RewriteEngine On RewriteRule ^blog-[^-]+-([0-9]+).html$ index.php?act=blog&id=$1
This should match everything except a - between blog and the id.
Now you should be able to call, e.g., *yousite/blog-some_title_or_other-494.html* and it will call index.php?act=blog&id=494. This new rule shouldn't break any of your old backlinks either. If it does, let me know and I'll fix it.

Categories