hiding query string parameters htaccess - php

Hi I want To Ask How Can I convert http://abc.tk/comments.php?post_referrel_id=16 to http://abc.tk/comments.php?post_referrel_id/16 using .htaccess mod_write
means the user see this link
abc.tk/comments.php?post_referrel_id/16
when he clicks a hyperlink having source
abc.tk/comments.php?post_referrel_id=16

you need research, sir.
check this easy tuto
And for your tips, don't use ? in the rewritten url.
here is a quick code to do that (with ? in the rewritten url)
RewriteEngine on
RewriteRule ^comment.php?post_referrel_id/([0-9]+)$ comment.php?post_referrel_id=$1

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^comments.php?post_referrel_id/(.*)$ comments.php/post_referrel_id=$1 [L,QSA]
You may have to add a redirect from one form to another. The above code just tells the server that the /16 is the same with =16

use these lines of code :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^abc.tk
RewriteRule ^comments.php?post_referrel_id=([0-9]+)$ comments.php?post_referrel_id/$1 [R=301,L]
this will be redirect comments.php?post_referrel_id=16 to comments.php?post_referrel_id/16

Related

How rewrite TWO URLS for .HTACCESS?

One pages of site have such adds: domain.com/posts/name.php
Other pages of site have such adds: domain.com/pages/name.php
I need to cut from these adds posts/ and pages/ only.
Firstly, I tried to use in .htaccess next rules:
RewriteRule ^([A-z0-9-]+)$ /posts/$1
RewriteRule ^([A-z0-9-]+)$ /pages/$1
Don't help.
Secondly, I tried to use in .htaccess such rules and conditions:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ posts/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ pages/$1 [L]
As result: image of mistake 404
Also I tried to use such method:
RewriteCond %{REQUEST_URI} ^([A-z0-9-]+)$/(posts|pages)/([A-z0-9-]+)/$1 [NC]
RewriteRule .* domain.com/%1%3
Don't help....
what i am understanding you need to remove the post and pages from the url following code will help you for that.
You would need the rewrite module of Apache: mod_rewrite.
Then do something like this:
RewriteEngine on
RewriteRule ^post/(.*)$ $1
RewriteRule ^pages/(.*)$ $1
Here is the official documentation of mod_rewrite: click
please test it onece I dint test the code but did same for replacing url and its work for me.
Thanks.
The solution of this problem such:
We enter all information about the page in the MYSQL database:
image of database
We generate a page from the database:
generation of page (php)
Set the generated page for Human-Friendly Url:
file .htaccess
So everything works, and POSTS there are in their folder in the database, and PAGES in their folder.
folder in database
All is clean. If you can do better somewhere, then correct me, please.

Can not Rewrite a URL with my .htaccess file

I'm having trouble rewriting a URL on my website to make it more presentable and easier to find on search engines.
I want to turn this:
http://www.gamingpopulace.com/threads/index?threadName=Glitches
Into this:
http://www.gamingpopulace.com/threads/Glitches
I'm currently using a .htaccess file with this in it:
RewriteEngine On
RewriteRule ^threads/([A-Za-z0-9-]+)/?$ /threads/threadName=$1 [NC,L]
From what I've seen seen in other questions, this should work.
What goes wrong:
When I type http://www.gamingpopulace.com/threads/Glitches into the URL, it just gives me a 404 error saying that the page is missing. From my understanding it should load http://www.gamingpopulace.com/threads/index?threadName=Glitches, but with the changed URL. Though I might be misunderstanding that.
Any help is appreaciated.
Thanks
Hello and welcome to SO
(I cheated and used Google but amended the info according to your question.)
Source : How To Set Up Mod_Rewrite
RewriteEngine on
RewriteRule ^thread/([A-Za-z0-9-]+)/?$ threads/index?threadName=$1 [NC]
Remove / from this ([A-Za-z0-9-]+)/?$
Replace
RewriteEngine On
RewriteRule ^threads/([A-Za-z0-9-]+)/?$ /threads/threadName=$1 [NC,L]
with
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule ^threads/([^/]*)?$ /threads/threadName=$1 [L]
I am assuming your original url is working, try this in root dir,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^threads/([\w-]+)?$ threads/index?threadName=$1 [QSA,NC,L]

Simple mod rewrite query string but still failed

I want to create .htaccess mod rewrite but still have problem.
Suppose i created friendly URL like this :
mydomain.com/mypage/12345/title-of-news
I want that friendly URL process the below URL in hidden process :
mydomain.com/index.php?p=mypage&idnews=12345
Values of "p" and "idnews" are dynamic, so they will have different value.
I tried below code but still didn't work. Anything wrong?
RewriteBase /
RewriteCond %{QUERY_STRING} p=(\w+)&idnews=(\d+)
RewriteRule ^index.php /%1/%2 [L,R=301]
Any help would be appreciated. Sorry if this is duplicated question, if don't mind please tell me the answer link. Thanks a lot.
I think you don't need the RewriteCond you write there.
And you can use following rule
RewriteRule ^/?([0-9a-zA-Z_.-]+)/([0-9]+)/([0-9a-zA-Z_.-]+)$ index.php?p=$1&idnews=$2 [L]
If you want to change index.php?p=foo&idnews=bar to /foo/bar , try theses rules :
RewriteEngine on
##externally redirect "/index.php?p=foo&idnews=bar" to "/foo/bar"##
RewriteCond %{THE_REQUEST} /index\.php\?p=([^&]+)&idnews=([^&\s]+) [NC]
RewriteRule ^ /%1/%2? [L,R,NC]
##internally redirect "/foo/bar" to "/index.php?p=foo&idnews=bar"##
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?(.*)?$ /index.php?p=$1&idnews=$2 [NC,L]

add page name in the url using .htaccess

I just started .htaccess so I do not know too much about it, I try to google it but failed so I post my question here, I am sorry if the question is silly for you. My question is.
I use this code in .htaccess page:
RewriteEngine On
RewriteBase /learn/php/htaccess/
RewriteRule ^(.*)/(.*)$ index.php?n=$1&p=$2
when I enter this url:
http://localhost/learn/php/htaccess/page/number
it works fine. but I also want to add index.php (page name) in the url. I tried this:
http://localhost/learn/php/htaccess/index.php/page/number
AND
http://localhost/learn/php/htaccess/index.php?page/number
but failed. How can I do this?
I simply want to do that if I add another page then I am not sure but I have to use this code:
RewriteEngine On
RewriteBase /learn/php/htaccess/
RewriteRule ^(.*)/(.*)$ index.php?n=$1&p=$2
RewriteRule ^(.*)/(.*)$ another.php?x=$1&y=$2
but how can I open the another.php page with this format?
thanks
Try adding a few conditions to your rules:
RewriteEngine On
RewriteBase /learn/php/htaccess/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)$ index.php?n=$1&p=$2
As for routing to another page, you'll need to distinguish the difference between the two routes. For example, given a url:
http://localhost/learn/php/htaccess/foo/bar
where should it get routed to?
index.php?n=foo&p=bar
or
another.php?x=foo&y=bar
?
htaccess knows nothing about the content, only the URL and a regex pattern to match it, so unless you differentiate between the two, you can't route the same thing to two different scripts.
You can just make it easy like this
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?data=$1 [QSA]
in your index.php you put this code
$data = explode("/",$_GET['data']);
$page = $data[0];
$number = $data[1];

redirection technique to use

i want to redirect users to my site based on the url they typed into the address bar but i am problems as what to actually do. forgive me if i am not using the right term, i am a newbie.
this an example of what i want to achieve
www.mysite.com (is my site)
www.mysite.com/pizza (is what the user typed)
i want the browser to take the user to www.mysite.com if he types www.mysite.com and redirect the user to www.mysite.com/base/tweek.php?ref=pizza if he types www.mysite.com/pizza.
how do i do this?
Try adding this to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ /base/tweek.php?ref=$1 [L]
Also make sure you have mod_rewrite loaded.
You must create the .htaccess file in the root directory of the page, and write:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /base/tweek.php?ref=$1 [L,QSA]
I think (handwritten, not checked :) ).
Hope it helps, if You have any problems, try to read some htaccess tutorial.
Just use header at the top from your index.php:
header('Location: anotherindex.php');

Categories