I am newbie for LAMP dev environment. is it possible to change the apache responses with a Linux shell script? Let's assume Browser request www.sam.com/styles/main.css and I want to serve www.sam.com/styles/main_new.css not main.css. I want to do this by using apache or Linux script. is this possible ? (sometimes this may be a silly question :D)
Thanks!
Asoka
You can learn something about url rewrite. And it is not possible to change the apache response by a linux shell.
You can use mod_rewrite.
Create a file named .htaccess in the site root directory with the follow content:
RewriteEngine on
RewriteRule /styles/main.css /styles/main_new.css
Related
hi everyone i have just created website to myself and i editted links using .htaccess (111.111.111.111/list.php | like 111.111.111.111/list ) not include php extension. but when i put files into my linux server, it doesn't work my linux nginx server. when i write 111.111.111.111/list on the url box, it display 404 not found page. it wants to me write 111.111.111.111/list.php
and everything is working on my computer localhost. (i didnt buy domain name i just use only server's ip) please help me
by the way i apologize for my english.
Nginx does not support .htaccess-files because of performance reasons.
https://www.nginx.com/resources/wiki/start/topics/examples/likeapache-htaccess/
You have to do this inside of the nginx configuration file.
To remove the .php maybe this helps:
How to remove both .php and .html extensions from url using NGINX?
If you really need .htaccess, you have to use apache instead of nginx.
I have an .htaccess file for page redirecting. It works fine in wampserver, but in phpstorm, it doesn't work and phpstorm doesn't use .htaccess.
For example, this works in wampserver:
localhost/Example/Page
This doesn't work in phpstorm:
localhost:63342/Example/Page
// 404 Not Found
Any thoughts on this problem?
.htaccess is used by the Apache webserver. It's not used by the PHPStorm web-browser though. If you want to be able to use it there, you would want to setup the 'Web path for project root' and point it to the appropriate location, as set in an Apache vhost.
I'm making changes to some software.
What I would like to do is change part of the url. In all of the urls in my site, there is "index.php" in it. Example: "domain.com/index.php?action=area". I would like to change "index.php" to "view". Example: "domain.com/view?action=area".
From what I understand, this can be changed via htaccess. Although, htaccess is only for linux, correct? What about windows? How can this be done for both linux & windows?
You have mod_rewrite that an Apache module. It works under Linux and Windows as long as you're using Apache (on windows, it may be referred to as "Wamp", though Apache can also be installed by itself).
If you are using IIS, there's a URL Rewrite module that behaves similar to Apache's mod_rewrite. The syntax and sometimes the behavior of the rewrite engine isn't exactly the same as in Apache, so for simple things this should be fine.
You could also try to re-implement your Apache rewrite rules to use IIS's webconfig. There's some tools for doing this.
The mod_rewrite rules in question would look something like:
RewriteEngine On
RewriteRule ^/?view$ /index.php [L]
Pretty simple.
Is it possible to execute .htaccess file on Tomcat?
We are trying to get phphgadmin to work and so far we can only load the first screen that display some folder links. When we click on them we get a 404 error and we suspect it might be URL rewriting.
You can't run phpmyadmin on tomcat, because tomcat can't interpret php (nor it can interpret .htaccess)
What you need is Apache HTTP server, and if you need to also run Java, use mod_jk or mod_proxy_ajp (comparison) - a way to let apache serve what tomcat "produces".
My htaccess file is the following:
RewriteEngine On
RewriteRule ^blog/post/([0-9]+) /blog.php?post=$1
RewriteRule ^blog/page/([0-9]+) /blog.php?page=$1
RewriteRule ^work/([0-9]+) /work.php?ID=$1
The work.php rule is working, but the two blog rules aren't. They used to all work, but I recently moved my server. Any ideas why this would be?
Thanks in advance!
Edit:
Woah, I noticed that I had a work folder, but no blog folder, so I made one, and now this works. Any ideas why?
I just set up a (virtual) server on my local Apache 2.2 installation, running PHP 5.2 as a module. The server's document root contained only php files to (simplistically) process the examples you gave above (just echoing the parameters from $_GET). My .htaccess file at the document root contained only what you specified above, and nothing else. The document root did not contain the subdirectories /work or /blog (or /blog/post or /blog/page).
My setup did not have any problems at all rewriting the SEO-friendly URLs to the proper PHP files, which in turn echoed the parameter values I expected from $_GET.
There is something other than mod_rewrite requiring the existence of the subdirectories, and Apache is hitting (and thus requiring) it before it processes the rewrite rules. Not sure what it is, but it does not appear to be mod_rewrite, given the rules you have above.