I have a single point of entry on my website
mysite.com/admin/index.php?View=List&Model=User
All access to the DB/application is through this index.php file.
I would like to clean my URL from what is shown above to.
mysite.com/admin/List/User
The idea is to remove the key 'Model and 'View'.
I have found this link that looks very similar.
PHP/Apache: Rewrite rules with .htaccess
in htaccess file insert this code :
RewriteEngine On
RewriteRule ^admin/([^/]*)/([^/]*)$ /admin/index.php?View=$1&Model=$2 [L]
The rewritten URL:
http://mysite.com/admin/List/User
this site very useful for generate rewrite URL
http://www.generateit.net/mod-rewrite/
Create a file named .htaccess in your web root if you haven't already got one with the following:
# Turn the rewrite engine on (skip this if already done)
RewriteEngine On
# Redirect admin/List/User/ to admin/index.php?View=List&Model=User
RewriteRule ^admin/([^/.]+)/([^/.]+)/?$ admin/index.php?View=$1&Model=$2 [L]
This might work:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^admin/([^/]+)/([^/]+) /index.php?View=$1&Model=$2 [NC]
Add to .htaccess in the root folder of your website.
Related
I want to change the URL from:
http://localhost/rootdirectory/portfolio/project-1.php
To:
http://localhost/rootdirectory/project-1
I have used below code currently but it's not working
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^portfolio/(.*)$ /$1 [L,NC,R=301]
This code is rewriting my URL as http://localhost/project-1 instead of
http://localhost/rootdirectory/project-1.
This code is rewriting my URL as http://localhost/project-1 instead of http://localhost/rootdirectory/project-1.
The code you posted is "redirecting", not "rewriting", the URL from /portfolio/<project> to /<project>.
From your URL example it looks like you should instead be rewriting the URL from /rootdirectory/<project> to /rootdirectory/portfolio/<project>.php (assuming you have already changed the URL in your application). If the .htaccess file is located at /rootdirectory/.htaccess (as stated in comments) then you would need something like the following instead:
RewriteRule ^([^./]+)$ portfolio/$1.php [L]
And remove the RewriteBase / directive altogether.
go to the folder that contains all the files for your site.
form your cpanel copy all the files to your Public_html folder.
I have a single point of entry on my website
mysite.com/admin/index.php?View=List&Model=User
All access to the DB/application is through this index.php file.
I would like to clean my URL from what is shown above to.
mysite.com/admin/List/User
The idea is to remove the key 'Model and 'View'.
I have found this link that looks very similar.
PHP/Apache: Rewrite rules with .htaccess
in htaccess file insert this code :
RewriteEngine On
RewriteRule ^admin/([^/]*)/([^/]*)$ /admin/index.php?View=$1&Model=$2 [L]
The rewritten URL:
http://mysite.com/admin/List/User
this site very useful for generate rewrite URL
http://www.generateit.net/mod-rewrite/
Create a file named .htaccess in your web root if you haven't already got one with the following:
# Turn the rewrite engine on (skip this if already done)
RewriteEngine On
# Redirect admin/List/User/ to admin/index.php?View=List&Model=User
RewriteRule ^admin/([^/.]+)/([^/.]+)/?$ admin/index.php?View=$1&Model=$2 [L]
This might work:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^admin/([^/]+)/([^/]+) /index.php?View=$1&Model=$2 [NC]
Add to .htaccess in the root folder of your website.
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]
In my site root directory. there are donghua.php and index.php. now, is there a way to use .htaccess file to let the visitor access my site .the default shows example.com/donghua.php. not example.com/index.php. thank you. the server is Apache.
ps:The user still can access example.com/index.php
i using DirectoryIndex donghua.php in the .htaccess. the default page is ok. but when i access example.com/index.php it redirect to example.com/donghua.php. if i forbid it redirect how do i do?
If you have access to the virtual host config file (or you should even be able to do this in htaccess) you can set the DirectoryIndex to be donghua.php if you want, i.e. instead of something like this:
DirectoryIndex index.html index.php default.html
Just do:
DirectoryIndex donghua.php
So whenever someone goes to your website, example.com, your apache installation will read donghua.php as the default index file.
Change your redirection rule in .htaccess file for index.php. If you open the .htaccess file, you can find the follwing lines,
RewriteCond %{THE_REQUEST} ^.*/example.php
RewriteRule ^(.*)example.php$ http://www.test.com/$1 [R=301,L]
Change or remove this rule for index.php. Better remove or comment it then it won't redirect to another page
"RewriteCond" this code check the codition if the browser requesting the file name index.php. If the condition is satisfy, then the next line will execute that is "RewriteRule". This "RewriteRule" will redirect your URL.
Search and find the name "index.php" in .htaccess file. comment out that lines. syntax to comment is "#".
Example:
#RewriteCond
#RewriteRule
Take back up before changing anything in .htaccess file.
To make your URL lovely and suitable for search engine ranking.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com
RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /index.html HTTP/
RewriteRule ^index.html$ http://www.yoursite.com/ [R=301,L]
To redirect
redirect 301 /old-page.php http://www.yoursite.com/new-page.php
I would like to take requests for /somefolder/style.css and handle them with /somefolder/program.php
So, I put the following in my .htaccess file:
rewriteengine on
rewriterule ^style.css$ program.php?css=1 [R=302,L]
The result is that instead of redirecting to /somefolder/program.php, the server tries to redirect to:
/var/www/html/somefolder/program.php?css=1
How can I get rid of the /var/www/html/ in the redirect? I thought that since I just entered program.php in the .htaccess that it would default to the same folder.
Since this is a generic script that I will use in many places, I would like to avoid using rewritebase to specify the folder I'm in -- the .htaccess has to work in any folder without being modified.
Leave the R flag away and you will get an internal redirect:
RewriteRule ^style\.css$ program.php?css=1 [L]
Otherwise specify the full URL path you want to redirect to externally:
RewriteRule ^style\.css$ /program.php?css=1 [R=302,L]
Or for any arbitrary folder:
RewriteCond %{REQUEST_URI} (.*)/style\.css$
RewriteRule ^style\.css$ %1/program.php?css=1 [R=302,L]
I think the problem is that you are missing a ReWrite base statement.
Also the I would put the .htaccess file in the root directory of your site. That way you don't have to copy an .htacess file into every new directory you create. What if you want to change the name of your php file? You'd have to change every .htaccess file.
This is how I would redirect www.mydomain.com/orange/style.css to www.mydomain.com/orange/program.php?css=1 using generic rules:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)/style\.css$ $1/program.php?css=1 [L]