How Do I use mod_rewrite - mod-rewrite

I have a url with:
http://example.com/index.php
I want it to be
/index
I will need to use mod_rewrite to make a virtual folder for a PHP or HTML file with .htaccess.
RewriteEngine on
RewriteRule ^index.php$ index/
This is not working
Any answers?

I think you want reverse rule:
RewriteEngine on
RewriteRule ^index/?$ index.php

Related

How to mod-rewrite the url with custom extension

I need to change the pattern of my url from the normal path into a subdomain. I tried write the .htaccess but it's not work.
http://hello.com/sos/article.php?id=1&title=this-is-a-title.php
From the url above I want to:
Change the pattern to call the page so I remove sos before the domain as a subdomain. So I'd got http://sos.hello.com/
I need the variable to be replaced with forward slash and suffixed with .sos. As the story is about warning : article/1/this-is-a-title.sos
I wish I could have something like this:
http://sos.hello.com/article/1/this-is-a-title.sos
So I wrote :
RewriteEngine On
RewriteRule ^article/([^/]*)/([^/]*)\.sos$ /article.php?id=$1&title=$2 [L]
And guess what! It's not work. Please point me out. What I've done wrong???
I've got the answer after several tries:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.hello.com
RedirectMatch 301 ^/sos/$ http://sos.hello.com/mypage.php
RewriteRule ^article/([^/]*)/([^/]*)\.sos$ /article.php?id=$1&title=$2 [L]
save as .htaccess to the subdomain directory

mod Rewrite : Hide php extension & replace variable name by slash

Need help, It is basic Mod-Rewrite. But i am confused
My current URL:
http://example.com/category.php?fn=accounting-tax
Want look like this:
http://example.com/category/accounting-tax
Only Apache Mod-Rewrite, No PHP please
Update:
Is it possible without PHP?
Thank you
Add this to your .htaccess in your web root /
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} (^|&)fn=(.*)(&|$)
RewriteRule ^category\.php$ category/%2 [NC,L]
Assuming, you meant
/category.php?fn=accounting-tax should take you to /category/accounting-tax
without showing up on the address bar. If you want an external redirect use [R=301,NC,L] instead.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^category/([a-z0-9\-]+)/item/?$ /category.php?id=$1
</IfModule>

Escaped Fragment Redirect htaccess

my website (thedutchtilt.com) employs AJAX.
Now I know that whenever Google tries to crawl a page, e.g. #!stories/component_74511, it will turn that url into thedutchtilt.com/?_escaped_fragment_=stories/component_74511 .
My question is, how do I format a htaccess redirect so that the aforementioned site will map to the other one?
I've tried
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=stories/component_74511
RewriteRule ^$ http://www.thedutchtilt.com/full.html? [R=302,L]
but trying this just gives http://thedutchtilt.com/?_escaped_fragment_=stories/component_74511, which is my homepage.
I'm really confused now, and nothing seems to be working (sigh).
Kartik
Current .htaccess:
RewriteEngine on
RewriteOptions inherit
# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
RedirectMatch ^/$ /index.html
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=stories/component_74511
RewriteRule ^$ thedutchtilt.com/full.html? [R=302,L]
Thanks for providing .htaccess code. Problem is your this RedirectMatch line:
RedirectMatch ^/$ /index.html
Comment it out and try again. index.html should be loaded as default using this DirectoryIndex directive:
DirectoryIndex index.html

URL Rewrite for joomla

I wanted change this joomla link
http://www.asbhtechsolutions.com/component/search/?searchphrase=all&searchword=simple%20program%20for%20java
to
http://www.asbhtechsolutions.com/search/simple-program-for-java
How can I do this?
If you don't want to write your own router for the search component, the simplest way is to add a redirect to your .htaccess file.
I don't know about your joomla version, but i checked in joomla 1.5.26,
Just got to the joomla/components/com_search/controller.php
and Search the function search(), at the bottom of this function you find the line that call the url with JRoute class.
$this->setRedirect(JRoute::_('index.php'.$uri->toString(array('query', 'fragment')), false));
now dig something your self to change according to your need, or read some documentation on Joomla JRoute, don't forget to change according to your Joomla Version.. Hope this help you..
if you don't have enough experience with .htaccess try renaming htaccess.txt file to .htaccess. It's contained in your root directory of the Joomla installation.
Oh.. I've never seen a question about .htaccess like this before, it's not easy. I do not know if the code below would work. Just give a try to test this in your .htaccess file:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/search/([a-z0-9-_]+)/?$
RewriteRule ^(.*) /component/search/?searchphrase=all&searchword=%1
RewriteCond %{REQUEST_URI} ^/search/([a-z0-9-_]+)/([a-z0-9-_]+)/?$
RewriteRule ^(.*) /component/search/?searchphrase=all&searchword=%1\%20%2
RewriteCond %{REQUEST_URI} ^/search/([a-z0-9-_]+)/([a-z0-9-_]+)/([a-z0-9-_]+)/?$
RewriteRule ^(.*) /component/search/?searchphrase=all&searchword=%1\%20%2\%20%3
RewriteCond %{REQUEST_URI} ^/search/([a-z0-9-_]+)/([a-z0-9-_]+)/([a-z0-9-_]+)/([a-z0-9-_]+)/?$
RewriteRule ^(.*) /component/search/?searchphrase=all&searchword=%1\%20%2\%20%3\%20%4

Renaming PHP URLs with HTACCESS

I am building a web app that puts out a link like the following:
http://www.sample.com/?a=bj7phm
I would like for it to look something like this:
http://www.sample.com/BJ7PHM
Is this possible within the HTACCESS?
-B
In order to do URL rewriting, you first need to:
Make sure you have mod_rewrite enabled on your server.
Make sure you have the proper permissions to add rules to your .htaccess file.
(AllowOverride must be set to All or include FileInfo)
Then create the following .htaccess file in your web root:
RewriteEngine On
RewriteRule ^([\-_0-9A-Za-z]+)$ index.php?a=$1 [L]
You can customize RewriteRule as much as you want.
The first parameter is the regular expression to match the REQUEST_URI with (relative to the folder the .htaccess is in).
The second parameter is what you want to rewrite it to, $n being your match groups.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([0-9a-zA-Z+]{1,7})$?a=$1 [L]
</IfModule>

Resources