rewriting url for query strings - 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
RewriteBase /
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteRule ^comments\.php\?post_referrel_id/([^/]*)$ /comments.php?post_referrel_id=$1 [L,QSA]

RewriteEngine on
RewriteRule comments.php?(.*)/(.*)/$ /comments.php?$1=$2 [L]

A URL rewrite wouldn't matter in this instance, as your still using query strings. It would make more since to eliminate the Query string all together with something like:
http://abc.tk/comments.php/post_referrel_id/16
Nevertheless, this can be achieved using .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule comments.php?post_referral_id/(.*)$ /comments.php?post_referral_id=$1 [L]
</IfModule>
Which will still use the same code, but be recognized by a different URL.

Check this out.
RewriteEngine On
RewriteBase /
RewriteRule ^comments\.php\?post_referal_id/([^/]*)$ /comments.php?post_referrel_id=$1 [L,QSA]

Related

Rewrite URL using .htaccess (adding query string)

http://www.naissancebebe.com/index.php?fc=module&module=prenoms&controller=search&gender=boy
I want to rewrite this using .htaccess to this way
http://www.naissancebebe.com/boy.php
so this query string "index.php?fc=module&module=prenoms&controller=search&gender=boy" add in .htaccess file.
here is my code
#RewriteEngine On
RewriteRule ^boy.php /index.php?fc=module&module=prenoms&controller=search&gender=boy [L]
Try :
Options -Multiviews
RewriteEngine On
RewriteRule ^boy\.php$ /index.php?fc=module&module=prenoms&controller=search&gender=boy [QSA,NC,L]

Simple RewriteRule do not work at php/apache in htaccess

I do not know why, but this simple Rule will not work.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^rubbellos\.png/$ rubbellos/rubbelbild_png.php [NC,L]
RewriteRule ^rubbellos\.css/$ rubbellos/rubbellos_css.php [NC,L]
</IfModule>
If I copy the xyz/rubbellos/rubbelbild_png.php to browser it is OK.
My approach is to bring the request of rubbellos.png to the .php-file. But I get a file not found.
Thx for any hint in advance.
You have 2 errors:
use a RewriteBase since you're talking about a subdirectory /xyz/ in your question.
disable MultiViews option to avoid unexpected behaviour with rubbellos (virtual file and existing directory).
You can replace your current code by this one in your htaccess (which has to be in /xyz/ folder)
Options -MultiViews
RewriteEngine On
RewriteBase /xyz/
RewriteRule ^rubbellos\.png$ rubbellos/rubbelbild_png.php [L]
RewriteRule ^rubbellos\.css$ rubbellos/rubbellos_css.php [L]
Note: don't forget to replace xyz by your real subdirectory's name

how to rewrite a url with two variables using .htaccess

i want rewrite it with a .htaccess i have this url:
../index.php?page=details&id=123456
like this:
../detail/123456
but I do not really know how to do this. Could you help me to rewrite this url?
or give me a simple example that I can understand how it works
RewriteRule ^(.*)/([0-9]+)$ index.php?page=$1&id=$2&%{QUERY_STRING}
The first (.*) selects any string, e.g. "details". ([0-9]+) catches a number, in your case "123456"
Finally
&%{QUERY_STRING}
ensures, that additional parameters are added to your backendscript, too.
This should work:
RewriteEngine On
RewriteRule ^detail/([^/]*)$ /index.php?page=details&id=$1 [L]
Here is an example I use for my webpage when it's in a subdirectory.
# "learn/degree/index.php?d=mathematics" shows as "learn/degree/mathematics"
RewriteRule ^learn/degree/([a-zA-Z_-]+)$ learn/degree/index.php?d=$1
To complete it, remember to write at the beginning of the page this:
RewriteBase /
RewriteEngine On
Here's the 'full' .htaccess I use in my page to give you some idea.
#Redirect any www. to the page without it. Helps to keep user logged.
RewriteBase /
RewriteEngine On
rewriteCond %{HTTP_HOST} ^www.newfutureuniversity.org [NC]
rewriteRule ^(.*)$ http://newfutureuniversity.org/$1 [R=301,L]
Options +Indexes
Options +FollowSymlinks
# Finally working. Rewrite the user so "/student/Username" will internally be "/student/?user=Username"
RewriteRule ^student/([a-zA-Z0-9_-]+)$ student/index.php?user=$1
# Rewrite the disciplines so "learn/degree/1" will internally be "learn/degree/index.php?dis=1"
RewriteRule ^learn/degree/([1-4])$ learn/degree/index.php?dis=$1
# Rewrite the degrees so "learn/degree/mathematics" will internally be "learn/degree/index.php?d=mathematics"
RewriteRule ^learn/degree/([a-zA-Z_-]+)$ learn/degree/index.php?d=$1
# Rewrite the degrees so "learn/subject/2/5/7" will internally be "learn/subject/index.php?class=2&div=5&section=7"
RewriteRule ^learn/subject/([0-9])$ learn/subject/index.php?class=$1
RewriteRule ^learn/subject/([0-9])/([0-9])$ learn/subject/index.php?class=$1&div=$2
RewriteRule ^learn/subject/([0-9])/([0-9])/([0-9])$ learn/subject/index.php?class=$1&div=$2&section=$3
You have to make the links to ../detail/123456, then the script interpretes it internally as ../index.php?page=details&id=123456. If you don't want this, then you are looking for a redirect.
Try this
<IfModule mod_rewrite.c>
RewriteEngine on
Options +FollowSymlinks
# RewriteBase / add this if necessery, commented intentionally
RewriteRule ^detail/([0-9]+)$ index.php?page=details&id=$2
</IfModule>

.htaccess rewrite from base (http://domain.com/catch-this)

I wonder how I should do accomplish the following.
Catch URL's like the following:
http://domain.com/blue-boats send to myfile.php?header=1$
I don't want it to have this structure: http://domain.com/boats/blue-boats
I've tried this, but it doesn't work properly:
RewriteRule /$ myfile.php?header=$1
just put .htaccess in the documentroot of http://domain.com/ with similiar content to the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/([^/]*)/?$ /myfile.php?page=$1 [L]
</IfModule>
Try:
RewriteRule (.+) myfile.php?header=$1

apache rewrite static url to dynamic

I'm try to rewrite my url
http://www.domain.com/live/randomword
it should go rewrite to
http://www.domain.com/live/?cat=randomword
here are my tests:
RewriteRule ^live/(.*)$ /live/?cat=$1
RewriteRule ^live/(.*)$ live/?cat=$1
and all i have in the htaccess file is:
RewriteEngine on
You should try to add a RewriteBase / to your .htaccess and to suffix your rule with a [L] to say it's last rewrite rule ending with something like that:
RewriteEngine on
RewriteBase /
RewriteRule ^live/(.*)$ live/index.php?cat=$1 [L]
If this still doesn't work be sure to check that mod_rewrite is enabled
also you can do a [R,L] instead of [L] to see the redirection in the url and so have more info on what's going own.
hope this help
Have this code in your .htaccess file:
Options -MultiViews +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^live/(.*)$ /live/?cat=$1 [L,NC]
in rewrite rule the file name or extension in missing?
write rule like,
RewriteRule ^live/([a-zA-Z0-9_-]+)$ /viewcategory.php?cat=$1

Categories