Does PHP supports htaccess URL rewriting in Windows - WAMP Environment?
How can I use it?
Below is one example:
My existing file name and URL is like below:
http://localhost/um/api_user_registration.php?FIRSTNAME=first_name&LASTNAME=last_name&USERNAME=user_name&EMAIL=abc#abc.com
Can I use it like below:
http://localhost/um/UserRegistration.mac?FIRSTNAME=first_name&LASTNAME=last_name&USERNAME=user_name&EMAIL=abc#abc.com
In short, I want to access file as UserRegistration.mac instead of api_user_registration.php
Please suggest a way of doing.
URL rewriting is done using mod_rewrite, an apache module. Make sure that it's loaded (probably in httpd.conf) and then add this to the htaccess file in your /um/ folder:
RewriteEngine On
RewriteBase /um/
RewriteRule ^UserRegistration\.mac$ api_user_registration.php [L]
You can try like this:
RewriteEngine on
Options +FollowSymlinks
RewriteBase /yourproject
RewriteRule ^UserRegistration.mac/([^/]+)/(.*) api_user_registration.php?id=$1 [PT]
more info: http://goo.gl/EBzz6t
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'm having some problems with the .htaccess file. I'm working on a REST API and I'm rewriting my URL's, if I put .htaccess at the root of my server (localhost) everything works fine, but I actually don't want to put my .htaccess file there but in my project directory.
For example I want to type
http://localhost/myproject/player/id/etc..
and not just
http://localhost/player/id/etc...
The problem is that if I use
http://localhost/myproject/player/id/etc..
The redirection works correctly but in my controller.php file the Path variable I retrieve is /myproject/player/id. Is there a way to remove /myproject/ from the URI in the .htaccess file, or more generally is it possible to remove the directory of the folder containing the .htaccess from the REQUEST_URI variable ?
ok. try this- in your .htaccess write-
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^myproject/(.*)$ /$1 [L,NC,R]
it will remove myproject from your url.
i am working within sub folder of my website and i want to rewrite my urls.
i have never done this before nor have any knowledge of rewriting rules.
I have a file which named show.php which takes parameter id which is any no and then it echo that no on to the screen.
Now this file is in folder name polo.
www.xyz.com/polo/show.php
i want to rewrite
www.xyz.com/polo/show.php?id=10
to
www.xyz.com/polo/id/10
I tried this answer but still its not working.
Subfolders using htaccess
Any help would be appreciated.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(polo)/(id)/([0-9]+)/?$ /$1/show.php?$2=$3 [L,QSA,NC]
My URL looks like this:
http://127.0.0.1/website/comments.php?topic_id=16
I want to make it look like this:
http://127.0.0.1/website/comments/my-news-article/16.php
I have applied this
RewriteEngine on
RewriteRule ^comments/([a-zA-Z0-9_-]+)/([0-9]+)\.php$ comments.php?id=$2
I have also turned on Rewrite_module in Apache.
But it's not working.
Always consider the entire URL path. Yours includes /website, so:
RewriteEngine on
RewriteBase /website
RewriteRule ^comments/([a-zA-Z0-9_-]+)/([0-9]+)\.php$ comments.php?id=$2
RewriteBase is used for per-directory directives. Try
RewriteEngine on
RewriteRule ^/website/comments/([a-zA-Z0-9_-]+)/([0-9]+)\.php$ /website/comments.php?topic_id=$2
Works for me. Note that I also changed the query string parameter at the end of the line to "topic_id". Maybe this is another cause of error. If it still fails, check that the configuration is in the right virtual host config.
how to use different url structure in php ?
I want to know to handle url like this
www.example.com/10/2011
instead of
www.example.com/?m=10&y=2011
Maybe it will be better to do with server configuration - .htaccess (in Apache) or web.config (in IIS). Create rewrite rule from ^(\d+)/(\d+)$ to /?m=$1&y=$2. For example, in Apache it will look like:
RewriteEngine On
RewriteBase /
RewriteRule ^(\d+)/(\d+)$ /?m=$1&y=$2
this can be achieved through apache's mod_rewrite mechanism. create a .htaccess file in your webroot with the following contents:
RewriteEngine on
RewriteRule ^([0-9]+)/([0-9]+) ?m=$1&y=$2 [NC]
similar mechanisms exist for other web servers.
You should use Rewrite(google it) engine in Apache or nginx.
Something like this exists in ISS too.
This is not achieved by PHP, but by some other "component". E.g. the Apache web server has a module (the rewrite engine) that can rewrite the URL so that you can use URL like www.example.com/10/2011 and it translates them into www.example.com/?m=10&y=2011 so that in your PHP code you can use $_GET['m'] and get the month. Rewrite engine for Apache (for other webserver similar things may exist)
One easy method is something like this:
In your .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
What this does it redirects everyhting to index.php if its not a physical file or dir.
Then you configure your index.php to handle this request.
Example
www.example.com/10/2011
will become $_GET['10/2011'];
so you can use data in your script.