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]
Related
I have this folder system:
localhost/websites/2018/mywebsite
And there I have this file:
products.php
so the full route I type in my browser to access it is:
localhost/websites/2018/mywebsite/products.php
Now, I'm trying to use mod_rewrite to get this:
products.php?cat1=a&cat2=b&cat3=c
into this:
shop/a/b/c
So the full url would be:
localhost/websites/2018/mywebsite/shop/a/b/c
I tried putting the .htaccess in here:
localhost/websites/2018/mywebsite
with this code:
RewriteEngine On
RewriteRule ^shop/([^/]*)/([^/]*)/([^/]*)$ /products.php?cat1=$1&cat2=$2&cat3=$3 [L]
But when I go to
localhost/websites/2018/mywebsite/shop/
I get a 404. I think it has to do with the directory tree because when I upload it to the website (root directory) it works fine.
Edit: I tried using
RewriteBase localhost/websites/2018/mywebsite
And some variations but it didn't work. It threw 500 server error.
You would need to use %{QUERY_STRING} for this to work. Try something like the following:
RewriteEngine On
RewriteCond %{QUERY_STRING} cat1=(.+)&cat2=(.+)&cat3=(.+)$ [NC]
RewriteRule ^ /shop/%1/%2/%3/? [R=301,L,NE]
This grabs each of your variables and then rewrites /shop/a/b/c onto the end of your URL. The use of ? is there to stop the original query from appearing on the end of the URL.
Make sure you clear your cache before testing this.
I've just transferred a project of mine to the web and I have a file called "circlecrop.php" that's located in the root directory of where all the CodeIgniter files are. This php script basicall just makes any image with circlecrop.php?path=img cropped to a circle, very simple and it works fine locally.
This works perfectly fine locally.
I'm getting the following error:
Failed to load resource: the server responded with a status of 403 (Forbidden)
I can't access circlecrop.php directly even though I've got it set to 777, I haven't anything set within my routes in CodeIgniter I'm not sure it's needed?
Complete htaccess file
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|circlecrop\.php|images|js|profile_pictures|fonts|stylesheets|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
I've done some searching and can't seem to find anything, my only thought is that I need a way to directly access circlecrop.php and it will work. Any help is greatly appreciated!
Edit: I've updated the url that has the errors, maybe that's more helpful.
You need to include if your website placed on root directory
RewriteBase /
If it place in test folder for example use this.
RewriteBase /test/
simply use site_url() on every link and action instead of base_url().
This worked for me:
I replace .htaccess content by the following:
RewriteEngine on
RewriteCond $1 !^(index.php|application/themes|application/theme_path|images|assets|robots.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Update your base_url according to your live host in config.php
$config['base_url'] = 'SET YOUR SITE URL HERE';
config.php is located in /application/config
I'm trying to use GET to capture member IDs in a URL without using the ?name=variable. For instance, instead of using mydomain.com/folder?id=1234 I would like to use mydomain.com/folder/1234 and pick up the id "1234" in the code so I can pass it to another URL.
This page simply redirects by using: <iframe src="http://redirect_domain.com/folder/index.php" />
I have no control over the server I'm redirecting to, but need the variable passed to it. I can append the redirect URL with ?id=1234 ie <iframe src="http://redirect_domain.com/folder/index.php?id=1234" />
Their code will pick up the id by using <?php echo $_GET["id"]; ?>
Thanks for your help.
You'll want to use .htaccess for this. Create a file called .htaccess and put it in the same folder mydomain.com is referencing. Put something like the following in there
RewriteEngine On
RewriteRule ^folder/(.*)$ folder?id=$1 [L]
Note: mod_rewrite must be enabled on apache, but it usually is.
Update: I've updated the .htaccess to reflect a local URL since you've made your desired functionality more clear. Using this .htaccess in conjunction with <iframe src="http://redirect_domain.com/folder/index.php?id=<?=$_GET['id']?>" /> should do the trick.
Create a .htaccess file and use something like this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I feel the need to write my own answer down. The following two lines in your .htaccess should do exactly what you are asking for:
RewriteEngine On
RewriteRule ^folder/(.*)$ redirect_domain.com/folder/index.php?id=$1 [L]
According to the rewrite rule test site http://martinmelin.se/rewrite-rule-tester/ , when I use an input of folder/1234, it is redirected to redirect_domain.com/folder/index.php?id=1234 which is exactly what you asked for. There is no need for the <iframe... or any actual files in the /folder/ other than the .htaccess ...
I have a script that was written using codeigniter.
When accessed using a subdomain http://name.domain.com/admin/ it works fine but I now need to have the script installed in a folder and I cannot access http://domain.com/name/admin/ i just get a 404
I would guess (but I could be totally wrong) that it is a .htaccess issue.
RewriteEngine on
RewriteCond $1 !^(index\.php|install|updates|backups|images|css|js|uploads|jPicker|ckeditor|kcfinder|qr|fancybox|test\.php|licence\.txt|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
I would really appreciate any help to point me in the right direction so I can resolve this issue.
Thanks
{EDIT1}
With NO .htaccess file name.domain.com/, name.domain.com/admin & domain.com/name all work, it is only domain.com/name/admin that does not work.
When I add a .htaccess as above or the one in the second answer below the subdomain URL's still work but domain.com/name stops working and domain.com/name/admin continues not to work
You should exclude also your name folder on your .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|install|updates|backups|images|css|js|uploads|jPicker|ckeditor|kcfinder|qr|fancybox|test\.php|licence\.txt|robots\.txt|name)
RewriteRule ^(.*)$ /index.php/$1 [L]
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 :)