How to rewriting .php files to .asp - php

I am using below code for changing the URL but its not working. My folder structure is: www.abc.com/maindri/index.php
htaccess:
RewriteEngine On
RewriteRule ^home.asp?$ index.php
RewriteRule ^invesys.php?$ invesys-capital.php
RewriteRule ^stocks?$ stocks.php
RewriteRule ^performance?$ performance.php
Trying to change URL for first time.
I would like to show URL in browser home.asp intead that index.php

Try this
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^home\.asp$ index.php [T=application/x-httpd-php,L]

Related

htaccess redirect url to directory file

am working on making my site urls search engine friendly and for which am rewriting urls with GET parameters and so i have done rewriting but now htaccess is not pointing that url to php file which is suppose to handle the url
my old url
www.domain.com/foo/myfile.php?nid=554
new rewritten url with php
www.domain.com/foo/554-demo-page-title
my current htaccess rules which work for old urls but not for new
Options +FollowSymLinks
RewriteEngine On
#RewriteCond %{SCRIPT_FILENAME} !-d
#RewriteCond %{SCRIPT_FILENAME} !-f
RewriteBase /
RewriteRule ^([0-9]+)-(.*) ./foo/myfile.php?nid=$1 [NC]
so i want to that both old and new urls land on /foo/myfile.php becuase myfile.php can handle both urls incase of old url it rewrite and redirect as new url , i played for few hours with htaccess rules but no success
You can use this rule in site root .htaccess (assuming there is .htaccess inside foo/ directory):
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^foo/(\d+)-.*$ foo/myfile.php [L,QSA,NC]
If you already have /foo/.htaccess then use this rule inside that file:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /foo/
RewriteRule ^(\d+)-.*$ myfile.php [L,QSA]

Mod Rewrite htaccess rewriterule

I now have:
Order deny,allow
Options +FollowSymlinks
RewriteEngine on
DirectoryIndex index.php
RewriteRule ^en/newsevents$ ?action=setLang&lang=eng&menuid=6 [L,QSA]
It loads my texts but thiks it must look in the /en folder.
This does work, but changes the url from localhost/en/newsevents to localhost/name/?action=setLang&lang=eng&menuid=6
I want that it still remains localhost/en/newsevents
RewriteRule ^en/newsevents$ `http://localhost/name/?action=setLang&lang=eng&menuid=6 [L,QSA]`
Just do this:
RewriteRule ^(en/newsevents)$ $1?action=setLang&lang=eng&menuid=6 [QSA,L]
You need to use passthrough
RewriteRule ^en/newsevents$ ?action=setLang&lang=eng&menuid=6 [PT,L,QSA]

.htaccess for redirecting dynamic URL not working

I want to rewrite my URL:
http://jainpopulationregister.com/page.php?action=about
to:
http://jainpopulationregister.com/page/action/about/
with URL rewriting
My current URL rewrite code is as follows:
Options +FollowSymLinks
RewriteEngine on
RewriteRule page/action/(.*)/ page.php?action=$1
RewriteRule page/action/(.*) page.php?action=$1
But when I place this in my root folder, nothing seems to happen. What am I doing wrong?
You want to redirect from
http://jainpopulationregister.com/page.php?action=about
to
http://jainpopulationregister.com/page/action/about/
but your redirect rule does exactly the opposite. Assuming that you really want to redirect from /page.php?action=about to /page/action/about/, use the following configuration in htaccess:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^action=(.*)$
RewriteRule ^(.*)$ /page/action/%1/? [R=302,L]
RewriteRule ^page/action/([a-zA-Z0-9]+)/$ pages.php?action=$1 [NC,L]
In "pages.php" file get the action $_GET['action'];

hiding directory name in the URL

my site's directory is:
localhost/
includes/
includes/initialize.php
includes/user.php
includes/session.php
includes/database.php
public/
public/bootstrap/
public/css/
public/js/
public/dashboard/index.php
public/index.php
.htaccess(first htaccess file)
{
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/$1 [QSA,L]
</IfModule>
}
I'd like to have my url more neat, for example
when I type this: http://localhost I know it goes to http://localhost/public/
but the URL still is http://localhost
but the problem is when I type http://localhost/dashboard
unfortunately the URL will be http://localhost/public/dashboard/ on my browser.
I do not want to see the word public.
I think I should have another htaccess file under the public directory, but I do not know the suitable code for it.
Try this code in your DOCUMENT_ROOT/.htaccess file:
DirectoryIndex index.html index.php
RewriteEngine On
RewriteRule !^public/ /public%{REQUEST_URI} [NC,L]

.htaccess url rewrite not formatting properly

Currently I working through my localhost in MAMP. I have read and research for the proper way to allow .htaccess file url rewrite and was successful. But now, the file is not formatting the links at all as desired. For example I have three pages index.php, about.php and contact. I am using MVC for the frame working of my site. Is this a problem with the code in the .htaccess file or my localserver?
Currently links look like this when going from one page to another:
localhost/mvc/index.php?
localhost/mvc/index.php?p=about
localhost/mvc/index.php?p=contact
.htaccess should format the links to look like this:
localhost/mvc/index/?
localhost/mvc/about/?
localhost/mvc/contact/?
.htaccess:
<IfModule mod_rewrite.c>
# Turn on the engine:
RewriteEngine on
# Set the base to this directory:
RewriteBase /mvc/
# Redirect certain paths to index.php:
RewriteRule ^(about|contact|this|that|search)/?$ index.php?p=$1
</IfModule>
Replace your existing .htaccess code fully with this code:
Options +FollowSymLinks -MultiViews
DirectoryIndex index.php index.html
# Turn mod_rewrite on
RewriteEngine On
# Set the base to this directory:
RewriteBase /mvc/
# Redirect /mvc/index.php?p=page to /mvc/page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+mvc/index\.php\?p=([^\s]+) [NC]
RewriteRule ^ %1/? [R=302,L]
# Redirect /mvc/index.php to /mvc/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+mvc/index\.php\s [NC]
RewriteRule ^ /mvc/ [R=302,L]
# Internally forward certain /mvc/page/ to /mvc/index.php?p=page
RewriteRule ^(about|contact|this|that|search)/?$ /mvc/index.php?p=$1 [L,QSA,NC]
Replace
RewriteRule ^(about|contact|this|that|search)/?$ index.php?p=$1
with :
RewriteRule ^(about|contact|this|that|search)/\?$ index.php?p=$1
I just escaped the ? with a slash because, otherwise, you don't do this, the question mark will be interpreted and will means that the slash before it is optinal.

Categories