Use .htaccess to give form submissions clean URLs - .htaccess

I'd like to rewrite form submissions to clean URLs, so that example.com/search/go?term=foo becomes example.com/search/foo
How do I do this?

Use JavaScript:
<input type="text" id="search_term" />
<input type="button" value="Search" onclick="goSearch()" />
<script type="text/javascript">
function goSearch() {
var term = document.getElementById("search_term");
window.location = "http://example.com/search/" + escape(term);
}
</script>
URL encode the query string, and redirect to the desired path.

You can change the URL that is called in the action attribute of the form element in HTML. Alternatively, you could set it in an OnClick JavaScript event handler on a button.
You don't need mod_rewrite and .htaccess to accomplish this.
Though, you could use mod_rewrite to redirect everything that's not a document to an index controller script and do the translation there.
RewriteEngine on
RewriteBase /
RewriteRule !\.(js|ico|txt|gif|jpg|png|css)$ index.php
That's how Zend Framework does it, and actions look like example.com/search/foo instead of example.com/search/go?term=foo. Of course, search would need to be a script.

Related

Redirect to the same page after deleting an element

I have a current page with a query parameter - page number:
example.com/comments?page=2
Each page contains some comments. Comments can be deleted, and after deleting a comment, I need to make a redirect to the same page. Form to delete a comment:
<form action="/comments/delete" method="POST">
<button type="submit">Delete</button>
</form>
How can this be done in a simple way? So far, it redirects to the very first page, because the query parameter with the current page is not passed in any way when deleting a comment.

How do I load a local html file using webview

I am building an electron app where I am loading an html file using this code in development:
<webview id="foo" src="/src/documents/example.html" style="display:inline-flex; width:100%; height:550px"></webview>
This works well in development but once the app is packaged it shows a blank page.I have researched around and it seems using __dirname might fix the issue.
I am still very new to electron and can't figure out how to reach this path (src="/src/documents/) using __dirname.
Any help will be highly appreciated.
I thought I would share the solution I found around this.Basically ,you need to create a route for the page you want to load like this:
{
path:'/example',
name:'example',
component: require('#/components/example').default
},
If you are using electron-vue,make sure the page extension is ".vue" and enclose the page content like this:
<template>
<html>
**Put the page content in here**
</html>
</template>
In my case,I wanted to go to the page by clicking on a button,so i used Vue-router like this:
<button type="button" class="btn btn-light"><a id="home"><router-link :to="{ name: 'example' }"> Button text </router-link></a>
</button>
Et voila!

my action path in expressionengine search form has wrong value

I used EE ver 2.10 also use simple search tag like this:
{exp:search:simple_form channel="magazine-posts" result_page="/results"}
<input type="text" name="keywords" id="keywords" autocomplete="off"/>
{/exp:search:simple_form}
but redirect to index.php to show results. when I check HTML code in inspect element, I see form action path is: action="http://example.com/index.php that is wrong.
please help to resolve it.

Redirect front page with 301 using Prettyfaces

I use jsf 2.2 & prettyfaces-jsf 2-3.3.3 and have /pages/index.xhtml page.
I try redirect from front page to another like this:
<rewrite match="/" url="http://somesite.net" redirect="301" />
Of course, all the pages are redirected. What is the right way redirect only front page?
The match attribute is a regular expression. So you should try something like this instead:
<rewrite match="^/$" url="http://somesite.net" redirect="301" />

Relative URLs in Sharepoint master page

I have a master page with tabs. The tabs are defined by the following sitemap file:
<siteMap>
<siteMapNode title="Home" url="~/" >
<siteMapNode title="Schedule" url="~/Pages/Tab2.aspx"/>
<siteMapNode title="Deliverables" url="~/Pages/Tab3.aspx"/>
<siteMapNode title="My Items" url="~/Pages/Tab4.aspx"/>
<siteMapNode title="Management" url="~/Pages/Tab5.aspx"/>
<siteMapNode title="Working Docs" url="~/Pages/Tab6.aspx"/>
</siteMapNode>
</siteMap>
The problem is that on my subsites, clicking on a tab keeps taking me back to the root. For example, I want the schedule link to go to http://Server/Subsite/Pages/Tab2.aspx. Instead, what I am getting is http://Server/Pages/Tab2.aspx. I read that having a tilde at the beginning of the link would solve this problem but it doesn't.
I spent HOURS looking for the answer to this question, and it turns out there IS one, it's just annoying. You can use the ProjectProperty tag in WSS sites AND MOSS sites, and one of the possible parameters for ProjectProperty gives you the subsite's URL.
<SharePoint:ProjectProperty Property="Url" runat="server"/>
That outputs a string literal with the value of the subsite URL. So, for example, you can do this (note that you need to use single-quotes for the src='' or href='' attribute of the actual HTML tag):
<a href='<SharePoint:ProjectProperty Property="Url" runat="server"/>/pages/Tab2.aspx'>
Hope it helps! For a listing of other possible values for ProjectProperty, check out this guy's page (which is where i found my original answer!)
I was looking for an answer to do this for a long time... I want to package my site as a Site Template and having absolute URLs was not an option... I need them to be relative to what ever the site URL is... whether it is at the root of MOSS or a sub-site deep down in the structure...
I found the following to work:
Script Tags:
<script type="text/javascript" src='<asp:Literal runat="server"
Text="<% $SPUrl:~Site/appBin/js/jquery.min.js %>" />'></script>
Style sheet (Method suggested above by user385947):
<link rel="stylesheet" type="text/css"
href="<% $SPUrl:~Site/appBin/css/jquery-ui.css %>" />
Hope this helps others...
You're looking for the ~site token, here's a list of the URL tokens custom to WSS.

Resources