Sorry I changed the previous question. I have problem with .htaccess rewrite rule on localhost, I have .htaccess file in http:// localhost/testing/.htaccess.
I want to change url like below
http://localhost/testing/site.php?site=test
to
http://localhost/testing/test
And I have code in .htaccess as
RewriteEngine on
RewriteRule ^([^/\.]+)/?$ site.php?site=$1 [L]
Which is working correct, but I have also url like
http://localhost/testing/pages.php?site=test&pid=2
Here pages.php with two parameters as site name and page id. I want rewrite this as
http://localhost/testing/test/2
For both conditions I have bellow code which is not working
RewriteEngine on
RewriteRule ^([^/\.]+)/?$ site.php?site=$1 [L]
RewriteRule ^([^/\.]+)/?$ pages.php?site=$1&pid=$2 [L]
Please Help
Thanks :)
What you need to do is turn on the mod_rewrite on your Apache server by performing these steps:
Assuming you have unpacked the xampp folder in the C:\ directory, navigate to the folder containing the apache configuration files.
The full path is C:\xampp\apache\conf\.
In the conf folder, you will find a file named httpd.conf. This file holds all the configuration parameters for apache. Open the file in a text editor.
Search for mod_rewrite.so and you will come across a line as follows : #LoadModule rewrite_module modules/mod_rewrite.so
Uncomment the line by removing the hash (#) mark.
Save the file and restart Apache web server.
and also if the file is already in the testing folder your code should look like this:
RewriteEngine on
RewriteRule ^site\.html$ site.php?site_id=$1
I got solution which worked for me.
RewriteEngine on
RewriteRule ^([^/\.]+)/?$ site.php?site=$1 [L]
RewriteRule ^([^/]+)/([^/\.]+)/?$ pages.php?site=$1&pid=$2 [L,QSA]
Thanks everyone :)
Related
My .htaccess file contains:
Options +FollowSymlinks
RewriteEngine On
RewriteRule projects$ projects.php
RewriteRule projects/$ projects.php
RewriteRule projects/page/([^/]*)$ projects.php?page=$1
RewriteRule projects/page/([^/]*)/$ projects.php?page=$1
RewriteRule projects/company/([^/]*)/$ projects.php?companyid=$1
RewriteRule projects/company/([^/]*)$ projects.php?companyid=$1
RewriteRule projects/([^/]*)$ projects.php?id=$1 [L]
It was working fine, but suddenly this section is not working in my website.
This should redirect to "projects.php?companyid=$firstvariable",
but actually, I don't know why.
I tried restarting my PC and deleting temp and restarting WAMP.
After some interactive troubleshooting with OP, it appears that WAMP's Apache/PHP will execute a PHP file that matches the directory portion of the URL path if it exists, before applying the .htaccess RewriteRules.
In other words, if you have a file named Abc.php, and you request /Abc/def, WAMP's Apache/PHP will just execute Abc.php and not consult the .htaccess file.
I'm not sure if this is something special about WAMP and whether it's out-of-the-box behavior. I can't find any documentation on being able to control/change this behavior.
The problem I m facing that I am receiving an id from url and showing it simply
http://localhost/test/?username=bingo123
Its working fine and shows the result
But I want that I should be able to write like
http://localhost/test/bingo123 .
I tried to make .htaccess file and but it does not work and shows
The requested URL /test/bingo123 was not found on this server
Rewriteengine on
Rewriterule ^([a-zA-z]+)$ index.php?username=$1
I want to know that what should i change make in .htaccess file or some other settings in Wamp to run the script and where should I save .htaccess so that It works fine .Here "test" the folder name where all php files are there and how to save the .htaccess file as it does not allow it to save without first name.
Thanks in advance.
Try like this
RewriteEngine On
RewriteRule ^test/([^/]*)$ /test/?username=$1 [L]
Myabe Helpful
RewriteRule ^test/([a-zA-Z]+)$ test.php?username=$1 [L]
RewriteRule ^test/([a-zA-Z]+)/([a-zA-Z]+)$ test.php?username=$1/$2 [L]
RewriteRule ^test/([a-zA-Z]+)/([0-9]+)$ $ test.php?username=$1[L]
RewriteEngine On
RewriteRule ^test/([a-zA-Z0-9-=_.]+)$ test.php?username=$1 [L]
I am trying to use a .htaccess file to change my URLs from
xxx/table/change.php?id=1
to
xxx/table/change/1
I have the following code in my .htaccess file, which is in the root folder of my web site.
RewriteEngine On
RewriteRule ^change/([^/\.]+)/?$ change.php?id=$1 [L]
RewriteRule ^change/([^/\.]+)/?$ change.php?id=$1 [L]
However when I restart Apache and visit the desired URL, it still shows up as
xxx/table/change.php?id=1
Any suggestions?
mod_rewrite is uncommented in the httpd.conf file.
how about you use
change/(\d+)$ change.php?id=$1 [L]
that is when you visit
xxx/table/change/1
you are not redirected or 404, you get the correct page. is that what you are looking for?
In my page, when I write the url domain.com/abc it uses the htaccess RewriteRule ( posted below) and opens the company-profile.php page, showing the ABC profile. ABC IS AN EXAMPLE. IT MAY BE ANYTHING
However, even I have a domain.com/index.php file, when I write just domain.com and hit enter, it takes me to the company-profile.php page where it supposed to show the index.php file
My question is how can I fix this ?
RewriteEngine On
RewriteRule ^([a-z0-9]+)?$ /domain.com/company-profile.php?cid=$1 [NC,L]
Something like this maybe?
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_URI} !^/index.(php|html?)
RewriteRule ^(.*)$ profile/company-profile.php?cid=$1 [NC,L]
The first part of your RewriteRule is matching anything that's a combination of letters and numbers and passing it to your /domain.com/profile/company-profile.php script. You need to be more specific on your RewriteRule, i.e:
RewriteEngine On
RewriteRule ^/profile/([a-z0-9]+)?$ /domain.com/profile/company-profile.php?cid=$1 [NC,L]
The above will only match requests beginning with /profile/, so for example /profile/martinbean will be matched.
Is apache your web server. If the answer is yes, You should first check your loaded apache modules to see if the rewrite module is loaded. If not , then try to add this line:
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
to your apache config files . Then try to restart your web server to check if the rewirte rules worked.
http://codeigniter.com/user_guide/general/urls.html
I am using a MAMP setup
I access my codeigniter welcome message as follows
http://localhost:8888/CodeIgniter_2.0.2/index.php/welcome
the tutorial says
use a .htaccess file as
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
to get same message with
http://localhost:8888/CodeIgniter_2.0.2/welcome
but I get a 404 not found error instead
Try to add RewriteBase on your htacces file.
RewriteEngine On
RewriteBase "/CodeIgniter_2.0.2/"
...your rules here...
the last line should be
RewriteRule ^(.*)$ index.php/$1 [L]
and not
RewriteRule ^(.*)$ /index.php/$1 [L]
First things first, you need to check your httpd.conf
Look for this line.. (the location may not be the same)
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
Make sure it's uncommented. Then save your changes and restart apache server.
Also, make sure that the .htaccess file is in the same directory as your index.php.
It's usually the base directory of your CodeIgniter application.
EDIT:
Also forgot to mention that you need virtual hosts for this work seamlessly.
Argh, it seems your question is a repost. Here's another question but this is on a MAC OS X platform, with some detail on setting up your virtual hosts.
Remove "index.php" from URL - Codeigniter
the instructions you followed assume you are installing code igniter in the docroot, and not a subdirectory. move all your files in /CodeIgniter_2.0.2 down a directory.
mv CodeIgniter_2.0.2/* .