So I know the basics of URL rewriting, but there was something more complex that I couldn't get done or know if it can be done.
From:
http://www.example.com/file.php?name=Sam&id=23
To:
http://www.example.com/Sam/file/23
I basically want to know if this is possible and if it is, how it can be accomplished?
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /$2.php?name=$1&id=$3 [L]
Use the below htaccess redirection rule.
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/(.*)/(.*)/([0-9]+)$
RewriteRule ^(.*)/(.*)/(.*)$ /$2.php?name=$1&id=$3 [L]
To get the vales use in php
$_GET['name'];//Sam
$_GET['id'];//23
Related
I am actually trying to have the URL repointed via HTAccess using the Old Formating of the website:
https://fw1.work/actualites/details.php?ID=3191
to the new Formating. To do so I need to point it to the New URL Formating:
https://fw1.work/actualite.php?id=3191
Actually tried a couple of things online but nothing seems to be working the way I want it...
RewriteCond %{QUERY_STRING} ID=(\w+)$
RewriteRule ^actualites/details.php /actualite.php?id=%1 [L]
This is where I am at actually.
make sure rewrite mod enabled,
then let RewriteRule rgexp match the full url.
RewriteEngine On
RewriteCond %{QUERY_STRING} ID=(\w+)$
RewriteRule ^actualites/details.php(.*) /actualite.php?id=%1 [L]
You need to write the rules as follows :
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} id=(\w+)$
RewriteRule ^actualite.php$ actualites/details.php?ID=%1 [L]
I know that this site has many questions about URL rewriting. But as a newbie, I could not find the correct answer for my case.
My question is: I would like to rewrite the original URL like this: when user visit:
http://username.example.com/a/b/c/d/e/f/g/h...
the apache will process request as
http://example.com/index.php?user=username&a=b&c=d&e=f&g=h...
According to what I knew, the solution could be using QUERY STRING, but I don't know how to do that.
Any help will be appreciated! Thanks,
The first thing you need for this is to create Dynamic sub-domain. create dynamic subdomain link will help you in this. Use following config for your case:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule (.*) http://example.com/$1 [R=301,L]
RewriteRule ^([aA-zZ])$ index.php?user=$1
RewriteCond %{HTTP_HOST} ^(^.*)\.example.com
RewriteRule (.*) index.php?user=%1
once this is in place, you can add more conditions for the remaining parameters.
so I have a few different links on my website, and I am looking for some advice on how I can achieve this.
Some example links:
domain/index.php?page=commandCenter&ID=40
domain/index.php?page=view&action=edit&ID=40
domain/index.php?page=acpDashboard
I would like the rewrite to look like the following for each link:
domain/commandCenter/40
domain/view/edit/40
domain/acpDashboard
Though it seems in order for this to work, I need to have something in place for those variables.
The last link would not work, but
domain/acpDashboard/0/0
is what it needs to work.
Is this possible, and how would I go about it? I only have 3 different variables page, action, and ID.
Here is my htaccess atm!
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.php$ /index.php? page=$1&action=$2&ID=$3 [L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Thanks for any advice!
Your here is wrong you can reference .htaccess RewriteRule to preserve GET URL parameters this answer
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.php$ /index.php?page=$1&action=$2&ID=$3 [L]
I have a slight problem.
I have a site that uses these formats for viewing certain PHP documents:
domainname.com/server.php?id=14
domainname.com/changeserver.php?id=14
domainname.com/customize.php?id=14
I would like to make these:
domainname.com/server/14
domainname.com/changeserver/14
domainname.com/customize/14
I also have various URLs such as /index.php and /login.php I would like to clean up.
If someone were to type the original URL, such as /server.php?id=14, I would like it to redirect to it's clean URL.
If anyone can provide me with a config or help me along the way to making one that can do this, it would be greatly appreciated.
To prevent an infinite loop while externally redirecting the ugly url to the clean url and internally rewriting it back to the ugly url, you can use the THE_REQUEST trick.
#External redirect
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /(server|changeserver|customize)\.php\?id=([^&]+)\ HTTP
RewriteRule ^ /%2/%3? [R,L]
#Change above to [R=301,L] once all rules work as expected
#Internal rewrite
RewriteRule ^(server|changeserver|customize)/(.*)$ /$1?id=$2 [L]
You need to rewrite your URLs in .htaccess file.
RewriteEngine On
RewriteRule ^server/(.*)$ server.php?id=$1 [R=301,L]
here is a good guide on URL rewriting
http://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/
In this case you have to use a 301 Redirect of URLS. Here is an example:
Redirect
www.example.com/a1/articles.php?id=1&name=abc
to
www.example.com/article/1/abc
For this you have to modify the .htaccess file with the following:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=(.*)&name=(.*)$
RewriteRule ^articles\.php$ /article/%1/%2? [R=301]
RewriteRule ^article/([^-]+)/([^-]+)$ /articles.php?article_id=$1&article_name=$2 [L]
RewriteEngine On
RewriteRule ^server/([A-Za-z0-9-_,()'+]+)?$ server.php?id=$1
RewriteRule ^changeserver/([A-Za-z0-9-_,()'+]+)?$ changeserver.php?id=$1
RewriteRule ^customize/([A-Za-z0-9-_,()'+]+)?$ customize.php?id=$1
To adapt to your code. Here is the answer.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^server\.php$ /server/%1? [R=301]
RewriteRule ^server/([^-]+)$ /server.php?id=$1 [L]
Check the Above code. I think this will help you.
I want rewrite the URL using PHP and/or .htaccess for when a user goes to http://mysite.com/profile they are acctually accessing http://mysite.com/index.php?page=profile
I'm a litte confused how to do this. Is this practice a good idea?
If mod rewrite is activated this should work in the .htaccess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?page=$1