.htaccess hide file- url bar - linux

How can I hide the name of a file in the url bar?
something like:
www.test.com/something/
and not
www.test.com/something/index.php

You need to use rewrite rules. If you use Apache web server than mod_rewrite is a good choice.
This manual should walk you thought the process of creating successfull rewrite rules : http://www.workingwith.me.uk/articles/scripting/mod_rewrite

Related

View rewrited URL in apache

I am getting some bugs hosting an application. The application uses rewrite rules. I did all tests possible and ensured that mod_rewrite is enabled in apache and the .htaccess file is being considered. I only want to visualize the URLs that is being genereted after considering the rewrite rule to continue the debug.
So my question is, given a .htaccess file with mod_rewrite turn on and rewrite rules defined in it, is it possible to view the final URL that is generated after considering the the rewrite rules ?
You can append %f to your LogFormat. This will show you the final filesystem path, which is more concise than looking at mod_rewrite tracing.

htaccess URL redirect based on page title

I would like to add a line to my htaccess to change this url:
RewriteEngine on
do this is the url
http://site/Calendar/viewevent?eventid=9223
into something like this :
http://site/Calendar/viewevent/Title-of-event
its php and joomla and I am a php developer, please dont advise me to use a component or module to handle redirects, I am trying to achieve this using .htaccess ONLY :) thank you in advance!!
Your 'pretty' url contains information that is not in the 'working' url. Besides that, the 'working' url also contains information that is not in the pretty url. You need database access to translate the event id to a seo-title, and the seo-title back to an event id. In other words: It is impossible to do this with .htaccess only, unless you change 'viewevent' to accept an event by seo-title, instead of eventid.
Mod_dbd can possible be used, but only in the server config file, not .htaccess.
As Sumurai8 says htaccess cant transform url like you want automatically.
But you can use Redirect 301 (or its variation) for one url to another.
for your example:
Redirect 301 /Calendar/viewevent?eventid=9223 /Calendar/viewevent/Title-of-event
more information here

how to rewrite joomla pagination to friendly url with htaccess

I want to rewrite pagination URLs http://mydomain.com/category?start=15 to http://mydomain.com/category/start/15, but I don't know how to achieve this with .htaccess.
PS: those URls ( http://mydomain.com/category?start=15) are referenced in search engines so I need to add 301 redirect to my new URLs.
I want mention that I already enabled SEF mode in Jommla configuration
First, if you want your URLs to look like /start/15 you have to rewrite them from the pretty format to the internal, not otherwise.
I currently have no access to an Apache, but your expression should look something simliar to this:
RewriteRule ^category/start/([0-9]+)$ http://mydomain.com/category?start=$1 [QSA,L]
Then, it would be neccesary to tell Joomla how to generate the pretty URLs, this happens without the htaccess file, for example in a SEO plugin.
Finally, to output 301 messages, you will want to add "Redirect" commands to your .htaccess file. Redirect incoming ?start=15 URLs to the pretty format. Make sure that this does not happen after your Rewrite...

how can i hide the part of url using .htaccess

I am trying to remove the part from my url here is the url "http://example.com/custom_joomla_template-2.5.6/about-us/portfolio/itemlist/category/3-category-2"
Now I want to remove "itemlist/category/" from the url so that url can be look link "http://example.com/custom_joomla_template-2.5.6/about-us/portfolio/3-category-2"
I am using default functionality of joomla i.e. SEF urls, I need to simplify it more I am new for the htaccess
Please suggest link for learning how to write rules for .htaccess file
Please help
Easiest thing is just to make a menu link somewhere that goes directly to category-2. That will set up the url correctly. It will also get rid of the 3-

Rewrite rules to hide an url

i need to hide full path and show shortly:
www.site.com/this/is/path/to/hide/page.php --> www.site.com
Any idea to do it with .htaccess apache and rewrite rules??
EXAMPLE:
If i type www.site.com i want open index.php (in /),
but if i go to /hidden/path i want to open file.php (in hidden/path)
mantaining browser url in www.site.com.
EDIT:
i want to see in the browser bar www.site.com and i want to open page at /this/is/path/to/hide/page.php .
thanks
As I explained in : How does url rewrite works? every rewrite triggers a new call to the rewritten URL. (HTTP 3xx code).
So the client will ask for www.site.com/this/is/path/to/hide/page.php, would be redirected to www.site.com and will be served the index page as a normal user.
There is no way to tell the client to display one URL in the browser bar instead of another, client browser will always make a new request. (Or you could impersonate any site for example)
If you are not against the use of a cookie, or can use environment variable you may be able to do something like :
RewriteRule this/is/path/to/hide/page.php / [co:knowHiddenPath=true]
The environment variable as same syntax with E instead of co.
(See http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html for cookie information)
Your index page should then check this cookie/variable to serve the hidden page or not.
Another solution would be to enable access with password to your file. So even if someone know the URL he would not access the file. Security by obscurity is does not exists.
You can I believe do that with an Alias,
Alias / /this/is/path/to/hide/page.php
This directive needs to be in your <VirtualHost>
This will use mod_rewrite and you can put this into your .htaccess
# Activate Rewrite Engine
RewriteEngine On
# Home page rewrite rule
RewriteRule ^$ /this/is/path/to/hide/page.php [QSA,L]
This will ONLY work if you hit website root (e.g. http://www.example.com/)

Resources