Want to rewrite url using htaccess - php

I am new to htaccess and want to do following thing,
I want to rewrite url like,
http://example.com/test/test.php to http://example.com/test.html
and my htaccess file present in test folder. Can anyone help to find out this problem.
Thank You

That should do it:
RewriteEngine on
RewriteRule ^(.*).html$ test/$1.php [QSA]

Related

Rewrite rule for url in php in .htaccess file

I want to use rewrite rule for may website.
I have a link
www.mysite.com/product.php?p_id=1212
Need to convert like
www.mysite.com/product/1212
Please suggest me the rewrite rule for .htaccess file.
Thanks in advance.
please add this rule in your .htaccess file
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^product/([0-9]+)/?$ product.php?p_id=$1 [NC,L]

htaccess rewrite url to css on WordPress site

I want to rewrite url to css-files(looks like http://localhost/wordpress/my-page/assets/css/style.min.css) to new path (http://localhost/wordpress/my-page/my-project/app/assets/css/style.min.css). How can i do this?
Please use following code in .htacess file.
RewriteRule ^/wordpress/my-page/assets/css/style.min\\.css$ http://localhost/wordpress/my-page/my-project/app/assets/css/style.min.css [L]

Rewrite URL using htaccess php

I want to rewrite the url in my project.
For example:
http://www.example.com/dashboard/test/ to http://dashboard.example.com/index.php
Also I want to do it for:
http://www.example.com/dashboard/test2/ to http://dashboard.example.com/index.php
Can anyone tell me the idea to rewrite the url?
First you create a .htaccess file in your root.
Than, just put the redirect commands in it.
How to compose a .htaccess and how to create rewrite rules is explained here: http://net.tutsplus.com/tutorials/other/the-ultimate-guide-to-htaccess-files/
You will need something like:
RewriteRule ^(.*)$ http://dashboard.example.com/$1 [L,QSA]
try this
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^test.*$ http://dashboard.example.com/index.php [R=301,L]

URL Rewriting in Apache Not Working For Me

I am using WAMP and has created a website in a 'http://localhost/snap2/html' folder. I am trying to execute following Rewrite rule but this is not working for me.
Server is giving me an error below:
The requested URL /snap2/html/browsed.html was not found on this server.
My .htaccess file is located in html folder and its structure is as below:
`RewriteEngine On
RewriteRule ^decision/([0-9]+)$ /snap2/html/decision.php?PanelID=$1`
Website is in a structure like 'www/snap2/html
Infact I am trying to rewrite following url
http://localhost/snap2/html/decision.php?PanelID=20
in to
http://localhost/snap2/html/decision/20
Also Options +FollowSymLinks gives me an error 500 therefore, I have commented it.
Any help would be pretty much appreciated.
Try this:
RewriteEngine On
RewriteRule RewriteRule ^snap2/html/decision/([0-9]+)$ /snap2/html/decision.php?PanelID=$1
But I guess this is not what you want. But maybe you will see where you wrong.
Symbol ^ in regular expression means that following string should be at the beginning of URL. so you have to include entire path, see htaccess RewriteEngine for more examples
Your write RewriteRule twice. Try
RewriteRule decision/([0-9]+)$ /snap2/html/decision.php?PanelID=$1 [L, QSA]
Or
RewriteRule snap2/html/decision/([0-9]+)$ /snap2/html/decision.php?PanelID=$1 [L, QSA]

Apache Rewrite rule confusion

I'm trying to convert a simple url (below) in to a blog-style url, but not quite sure how to do it, all of my other rules are working fine, but I can't seem to figure this one out.
URL I want to convert: http://www.website.com/myblog.php?id=1&title=My+blog+title
URL I want it to create: http://www.website.com/1/my-blog-title
What should the rule be?
Any assistance appreciated :)
Try this
RewriteEngine on
RewriteBase /
RewriteRule ([0-9]+)/([^.]+) myblog.php?id=$1&title=$2
Try this in your .htaccess file:
RewriteEngine on
RewriteRule ^(\d+)/([^/]+)$ myblog.php?id=$1&title=$2
But here the hyphens are not replaced by plus signs.
in your .htaccess file,
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /myblog.php?id=$1 [L]
You don't (well shouldn't) need to pass the blog title to the blog file, only the ID. Hope this works

Categories