I am on Centos 6.5 with Apache2 and Perl 5.23. I need to pass all traffic to the single perl script, check this request in a database, and show needed content (have both static and dynamic content).
The problem is I don't know how not to get caught to the infinite loop in mod_rewrite.
F.e. first time I pass a request to a script script sees that the user needs a static content and redirects it to the needed page, but this way the user gets to the .htaccess rules again.
I thought to add some kind of a parameter, but not sured. Need your help!
Related
Problem
I have an Apache server, and I'm trying to add my own custom analytics to it. What I want is to have the server call a script whenever a page is requested, and for that script to record the requested URL.
If it's not possible to run an external command, I'd want Apache to POST to a URL to record the page visit.
Research
I've tried searching for a way to run an external command from Apache, but everything I've seen is a CGI script. I don't want to change how Apache handles the URL, I just want a way to give it to a script to record it.
Question
Is there a way I can have Apache run an external command or POST to a URL whenever a page is requested?
Apache already records the URL for every request - in the access log. Further, its trivial to drop in a filter script between Apache and the file if you want to trigger more complex and specific side effects.
I don't want to change how Apache handles the URL
Why do you believe using a script handler (no sane person uses CGI nowadays) will change the way the request is handled?
Perhaps if you explained why you want to record the URL you might get more appropriate answers.
We have a db which has from and to mappings of URL to redirect. Whenever someone wants a new redirect rule, instead of adding the rule in Apache we add them to the DB. A function does a lookup from the DB and does the redirect on each request.
We now want to replace that DB and instead use a new System which we have got in place. It is a content management system and hence we can host .txt files in it.
Ideally, i want to make a GET call to domain/rewrite.txt file in Apache and read the rules and if the request matches any of the rules then do a redirect.
I looked at the documentation here and found the only way to do this is to use the external rewriting program for this. Still things aren't making sense. Can anyone help how to do this?
I have the following:
host/~username/
sends the browser the page /home/username/public_html/index.html. In another directory /home/username/site_root/ we have the root of a website starting with its own /home/username/site_root/index.html.
How to do this: I would like that host/~username/ sends the browser to /home/username/site_root/index.html, if possible keeping host/~username/ as the address in the address bar.
I have never done anything with Apache. Reading some answers it seems that I might be able to do this by adding a file /home/username/public_html/.htaccess with certain commands in it. I have tried imitating what they do with lines like
RewriteEngine on
Rewriterule <...>
but I haven't managed to produce any result.
I tried to avoid using the word redirect because I don't know if that is the name of what I want to do. I don't want it to load some page that then sends the browser to another location.
I saw another thing that is done modifying httpd.conf which changes the root directory of the Apache server. I don't have access to this file.
Have you tried something simpler like a symlink?
I have a little DNS Spoofing / Blocking system I setup for work. It simply uses a blacklist to spoof the dns records and simply points them to a BLOCK / DENY page.
If I go to the URL directly for instance http://www.redtube.com the system works as expected and displays my index.html and what it should
The problem arises if I go to http://www.redtube.com/video?/43 or anything other than the full domain I get a not found.
I need to to configure Apache so that it drops all the junk after the TLD and simply displays my page such as http://blocked.project.com
Another way to look at it would be to say redirect to index.html if the url entered is not known to the webserver.
Any help greatly appreciated.
Used an apache FallbackResource to achieve exactly what I was after. Had to make sure my image paths on the website were absolute but works a treat.
http://httpd.apache.org/docs/2.2/mod/mod_dir.html#fallbackresource
I have the following URL format:
www.example.com/members/admin/projects/?projectid=41
And I would like to rewrite them to the following format:
www.example.com/avits/projectname/
Project names do not have to be unique when a user creates them therefore I will be checking for an existing name and appending an integer to the end of the project name if a project of the same name already exists. e.g. example.project, example.project1, example.project2 etc.
I am happy setting up the GET request to query the database by project name however I am having huge problems setting up these pretty url's.
I am using Apache with Nginx Admin installed which mens that all static content is served via Nginx without the overhead of apache.
I am totally confused as to whether I should be employing an nginx rewrite rule in my nginx.conf file or standard rewrites in my .htaccess file.
To confuse matters further although this is a rather large custom appliction it is build on top of a wordpress backbone for easy blogging functionality meaning that I also have the built in wordpress rewrite module at my disposal.
I have tried all three methods with absolutely no success. I have read a lot on the matter but simply cannot seem to get anything to work. I am certain this is purely down to a complete lack of understanding on with regards to URL rewriting. Combined with the fact that I don't know which type of rewriting should be applicable in my case means that I am doing nothing more than going round in circles.
Can anyone clear up this matter for me and explain how to rewrite my URLs in the manner described above?
Many thanks.
If you are proxying all the non static file requests to Apache, do the rewrites there - you don't need to do anything on nginx as it will just pass the requests to the back end.
The problem with what you are proposing is that it's not actually a rewrite, a rewrite is taking the first URL and just changing it around or moving the user to another location.
What you need actually takes logic to extrapolate the project name from the project ID.
For example you can rewrite:
www.example.com/members/admin/projects/?projectid=41
To:
www.example.com/avits/41/
Fairly easily, but can you map that /41/ in your app code to change it to /projectname/ - because a URL rewrite can't do that.