Godaddy question mark and variable name hide php get - php

I have been trying for the past few days to get a Godaddy hosted server to hide the question mark and the variable name in the url automatically (ie. mysite.com/?id=5 >>> mysite.com/5) using Rewrite Rules in the .htaccess file.
My current .htaccess file looks like this:
RewriteEngine On
Options -MultiViews
RewriteBase /
RewriteRule ^/(.*)$ /index.php?id=$1 [P]
Am I doing something wrong or is it the Godaddy servers? Thank you in advance!

Try adding the following into your .htaccess file.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^index/(\d+)*$ ./index.php?id=$1
You can learn more about clean urls here: http://www.desiquintans.com/cleanurls

Related

how to redirect to specific file by writing rule in .htaccess file?

I have developed a project without using any framework. I want to redirect a page to specific php file (example : movie/movie.php) when click on this
Click me
link. I have created .htaccess file and currently it look like this.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/movie/([0-9]+)/$ http://localhost/tthtml/movie/movie_review.php [L]
</IfModule>
I have enable mod_rewrite module in httpd.conf file. I am using wamp server in windows machine.
I dont no how to do this. I have referenced few sites and I created this above rule in my own. Kindly any one help me to do this and feel better if your answer have explonation as well. Thanks in advance.
Modify the rule as follows:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^movie/([0-9]+)/(.*)$ http://localhost/tthtml/movie/movie_review.php [L]
</IfModule>
The rule that you placed was not working because it was comparing only the string "/movie/1/", while you actually want to match "/movie/1/Baashha-Suresh-Krishna-1995".
For this to work, I have modified the RewriteRule directive as ^/movie/([0-9]+)/(.*)$ to accommodate the remaining string "Baashha-Suresh-Krishna-1995" or any other value that the application may have.

Use Mod Rewrite to change site URLs [duplicate]

This question already has answers here:
Url rewriting mod_rewrite
(3 answers)
Closed 6 years ago.
Im pretty new to Apache's mod_rewrite and I'm trying to change how my URLs are displayed in the address bar. For instance I want
www.example.com/index.php
to be
www.example.com/home
and
www.example.com/products.php
to be
www.example.com/products
and so forth. So far I have this in mind but it's not working
RewriteRule ^home$ /index.php [L]
You need to do the following:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.example.com/home/$1 [R=301]
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.example.com/products/$1 [R=301,L]
You can either put this on httpd.conf in apache or in .htaccess file.
L means - Last - stop processing rules
You can try this. Edit the .htaccess file contents as:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>
This will redirect an url like this: example.com/any_path.php to example.com/any_path. To be precise, you are removing the .php extension from any PHP file.
Note:
For specific url, replace ([^\.]+) in the RewriteRule with the text.
Specify a correct path for RewriteBase in case you are using a subdirectory.
mod_rewrite should be turned on for your server system. Google a bit for turning on mod_rewrite in your system.

URL Rewriting in PHP With Parametres

I am using Wamp server that is localhost is my server and "mysite" is my site folder name in WWW direcotry
Here is my URL
..../mysite/videos/show.php?id=535&category=books
want this
......./mysite/videos/show/id/category
My .htacces code is:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^videos/show/(.*)/(.*)$ /videos/show.php?id=$1&category=$2
But it is not working any help...
I had the same problem 1 month ago. I found the answer thanks #anubhava. He`s suggestion work perfectly for me give it a try i hope to help you.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+videos/show\.php\?id=([^&\s]+)&category=([^&\s]+) [NC]
RewriteRule ^ /videos/show/%1/%2? [R=301,L]
RewriteRule ^videos/show/([^/]+)/([^/]+)/?$ /videos/show.php?id=$1&category=$2 [L,QSA,NC]
Try something like this:
RewriteEngine on
Options +FollowSymlinks
RewriteBase /mysite
RewriteRule ^videos/show/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)$ /videos/show.php?id=$1&category=$2
And Check mod-rewrite module of apache must be enable. If not than enable it and restart your server again.

.htaccess Mod Rewrite 'pretty ur'l to actual doesn't work

I'm trying to get htaccess to rewrite this url :
http://127.0.0.1/papercut3/article/post-title/
to this:
http://127.0.0.1/papercut3/article.php?p=post-title/
My current .htaccess is:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^article/(\d+)*$ ./article.php?p=$1
RewriteRule ^section/(\d+)*$ ./section.php?s=$1
And my urls written in the code:
http://127.0.0.1/papercut3/article/execution-call-for-cinema-killer/
My problem is that when I click the link I get this:
Not Found
The requested URL /papercut3/article/syria-suffers-deadliest-month/ was not found on this server.
I'm using WAMP, the .htaccess is in the root of the /papercut3 directory with all the core files. Any help would be greatly appreciated!:)
If you can use .htaccess files, you want it to look like:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^article/(.+)$ ./article.php?p=$1
RewriteRule ^section/(.+)$ ./section.php?s=$1
Or, you can be slightly more specific with what is allowed, but the one in your question only allows character [0-9], this way it opens it up and let's the respective PHP files do the checking/error-handling.
You may find help in the log file of apache, but I think this is related to AllowOverride directive, which must be set to None.
As said in the documentation, you need AllowOverride to contain at least FileInfo.
Edit: By the way, your rule won't match any of your url since you expect a int \d but don't provide any in input.

How To Rewrite URL in php using htaccess file. what change in php code

I'm new in .htaccess file. i m searching on net but i m not able to change and rewrite URL in PHP...
E.G
Show URL Like :
localhost/web/site/view_project.php?vp=14
I want show my URL like
localhost/web/site/project/14/
In php i m use this code
href="view_project.php?vp=<?php echo $c_id>" echo $c_project_title
In .htaccess file I'm using
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^project/([0-9]+)/?$ /view_project.php?vp=1& [L,R]
Now please tell what need to change in PHP Code and HTACCESS file... I'm totally new in this.
Change your PHP code to this:
href="project/<?php echo $c_id>" echo $c_project_title
And then 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 ^project/([0-9]+)/?$ /view_project.php?vp=$1 [L,QSA,NC]
You need to use $1 instead of 1 as you have it now, for more see here: https://serverfault.com/questions/389684/how-can-i-store-request-uri-in-a-variable-manipulate-it-and-then-use-it-in

Categories