.htaccess url friendly in php - php

I want to turn a url in the url friendly.
my url:
http://www.builtbydoctors.com/qrcode/index.php?id=93
and i want this url friendly:
http://www.builtbydoctors.com/qrcode/**title**/93
the title changes depending on the id.
my problem is in the htaccess file in the creation of the regular expression. there have:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index/([a-z0-9-]+)/([0-9]+)/?$ /index.php?id=$2&nome=$1 [NC]
</IfModule>
I know that the problem is in the htaccess file, can help me solve this problem in regular expression?

Your rule will work for url
http://www.builtbydoctors.com/index/title/93
If you want use it for your example then you should change your rule to
RewriteRule ^qrcode/([a-z0-9-]+)/([0-9]+)/?$ /index.php?id=$2&nome=$1 [NC]

Try to do so
<IfModule mod_rewrite.c>
RewriteEngine On
# Using this you can tell Rewrite to have a base url
RewriteBase /qrcode
RewriteRule ^([a-z0-9-]+)/([0-9]+)/?$ index.php?id=$2&nome=$1 [NC,L,QSA]
</IfModule>
Hope that works!

Related

htaccess rewrite rule knowledge

I want to rewrite the url of mysite with help of htaccess. My website url which I need to rewrite is given below.
http://getallfreedownloads.com/category.php?slug=business_directory_listing
Result needed
http://getallfreedownloads.com/business_directory_listing or http://getallfreedownloads.com/business_directory_listing/
I have used the below code for rewrite rule in my htaccess file
RewriteEngine On
RewriteRule ^([^/]*)$ /category.php?slug=$1 [L]
Please guide me what I can do to make it work fine.
Note: After adding rewrite rule I have removed the " category.php?slug= " from the a Tag
I will be thank full to you all.
try this once.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^/category.php?slug(.*)$ /$1 [L,NC,R]

Apache Rewrite rule doesn't work properly

I have written rewrite rule in .htaccess file as below:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule index/cat/(.*)/ index.php?cat=$1
</IfModule>
But this rule doesn't work.
I have this url /index.php?cat=auto%20loan and I want to change to /cat/auto-loan/.
So if you have any idea then please let me know.
Use this code
RewriteRule ^cat/(.*)/?$ index.php?cat=$1 [L,NC]
I have made forward slash at the end optional. You should not make it optional to avoid duplicate content issue(SEO) such as RewriteRule ^cat/(.*)$ index.php?cat=$1 or RewriteRule ^cat/(.*)/$ index.php?cat=$1. Choose a format and stick to it.

Rewrtting url by htaccess

localhost/visvabharati/archive.html/type/notice
this is my url.I want it to rewrite as
localhost/visvabharati/archive.php?type=notice
Please help me how would be the htaccess
currently using
AddHandler x-mapp-php5 .php
Options +FollowSymLinks
RewriteEngine on
#RewriteBase /
DirectoryIndex index.php?url_key=index [T=application/x-httpd-php,L]
RewriteRule ^([^/]*).html$ /index.php?url_key=$1 [T=application/x-httpd-php,L]
RewriteRule ^([^/]*).html-([^/]*)$ /index.php?url_key=$1&id=$2 [T=application/x-httpd-php,L]
But its giving 500.
Please Help me sort it out
Regards
This code here will do it for one page.
RewriteRule ^localhost/visvabharati/archive.html/(.+)/(.+) localhost/visvabharati/archive.php?$1=$2
If you need to do this for multiple pages, this should work.
RewriteRule ^localhost/visvabharati/(.+).html/(.+)/(.+) localhost/visvabharati/$1.php?$2=$3
Assuming visvabharati is a directory.
Place this in /visvabharati/.htaccess:
RewriteEngine on
RewriteBase /visvabharati/
RewriteRule ^([^.]+)\.html/([^/]+)/([^/]+)/?$ $1.php?$2=$3 [L,QSA,NC]
Also you need to remove all the code shown in your question.

SEO friendly url in PHP htaccess

I use Godaddy Apache server to build my own blog, and I did some search of SEO friendly url tutorials, and applied the following code in my web root .htaccess file to transfer links like http://www.bgmemo.com/blog.php?url=2012/08/23/4-steps-to-initialize-Apache-Derby-10-9-1-0-in-Netbeans-7-1-1.html to http://www.bgmemo.com/blog/2012/08/23/4-steps-to-initialize-Apache-Derby-10-9-1-0-in-Netbeans-7-1-1.html :
RewriteEngine on
RewriteRule ^([a-zA-Z0-9-/]+).html$ blog.php?url=$1
RewriteRule ^([a-zA-Z0-9-/]+).html/$ blog.php?url=$1
But it does not work. The htaccess is working and other code in it is applied. Who can tell me what is wrong? Thanks in advance.
Try this:
RewriteEngine on
RewriteBase /
RewriteRule ^blog/([a-zA-Z0-9\-/\.]+)/?$ blog.php?url=$1 [L]
This is the correctly way for donĀ“t have problems with your .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^blog/([a-zA-Z0-9\-/\.]+)/?$ blog.php?url=$1 [L]
</IfModule>

How to use .htaccess to rewrite requests from image to PHP script?

I have a PHP script located at http://sb1.dev.codeanywhere.net/~a70097sb/hc/onlinestatus/image.php that requires two GET variables: ign and style. My .htaccess file is in the same directory as image.php.
I want requests of the form http://sb1.dev.codeanywhere.net/~a70097sb/hc/onlinestatus/{style}/{ign}.png to be rewritten to http://sb1.dev.codeanywhere.net/~a70097sb/hc/onlinestatus/image.php?style={style}&ign={ign}. How do I do this, as I have no experience with mod_rewrite, and wasn't able to get it to work using any of the tutorials I found on Google.
Tried this but it didn't work, I just get a 404 page:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteRule ^([^.]*)/([^.]*)\.png$ image.php?style=$1&ign=$2 [L,NC]
You're on the right track. The capture pattern ([^/]+) matches everything up to the next /, so you'll need two of those.
RewriteEngine On
RewriteRule ^([^/]+)/([^/]+)\.png$ image.php?style=$1&ign=$2 [L,NC]
Try something like that:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.mysite\.com [NC]
RewriteRule ^hc\/onlinestatus\/(.*)\/(.*)\.png /hc/onlinestatus/image.php?style=$1&ign=$2 [NC,L]
</IfModule>

Categories